"Too much words, maximum '%max%' are allowed but '%count%' were counted", self::TOO_LESS => "Too less words, minimum '%min%' are expected but '%count%' were counted", self::NOT_FOUND => "File '%value%' is not readable or does not exist", ); /** * Defined by Zend_Validate_Interface * * Returns true if and only if the counted words are at least min and * not bigger than max (when max is not null). * * @param string $value Filename to check for word count * @param array $file File data from Zend_File_Transfer * @return boolean */ public function isValid($value, $file = null) { // Is file readable ? #require_once 'Zend/Loader.php'; if (!Zend_Loader::isReadable($value)) { return $this->_throw($file, self::NOT_FOUND); } $content = file_get_contents($value); $this->_count = str_word_count($content); if (($this->_max !== null) && ($this->_count > $this->_max)) { return $this->_throw($file, self::TOO_MUCH); } if (($this->_min !== null) && ($this->_count < $this->_min)) { return $this->_throw($file, self::TOO_LESS); } return true; } /** * Throws an error of the given type * * @param string $file * @param string $errorType * @return false */ protected function _throw($file, $errorType) { if ($file !== null) { $this->_value = $file['name']; } $this->_error($errorType); return false; } }