00001 <?php 00025 require_once 'Zend/Validate/Abstract.php'; 00026 00033 class Zend_Validate_NotEmpty extends Zend_Validate_Abstract 00034 { 00035 const INVALID = 'notEmptyInvalid'; 00036 const IS_EMPTY = 'isEmpty'; 00037 00041 protected $_messageTemplates = array( 00042 self::IS_EMPTY => "Value is required and can't be empty", 00043 self::INVALID => "Invalid type given, value should be float, string, array, boolean or integer", 00044 ); 00045 00054 public function isValid($value) 00055 { 00056 if (!is_null($value) && !is_string($value) && !is_int($value) && !is_float($value) && 00057 !is_bool($value) && !is_array($value)) { 00058 $this->_error(self::INVALID); 00059 return false; 00060 } 00061 00062 $this->_setValue($value); 00063 if (is_string($value) 00064 && (('' === $value) 00065 || preg_match('/^\s+$/s', $value)) 00066 ) { 00067 $this->_error(self::IS_EMPTY); 00068 return false; 00069 } elseif (is_int($value) && (0 === $value)) { 00070 return true; 00071 } elseif (!is_string($value) && empty($value)) { 00072 $this->_error(self::IS_EMPTY); 00073 return false; 00074 } 00075 00076 return true; 00077 } 00078 00079 }