diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:39:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:39:39 +0000 |
commit | 8ca6cc32b2c789a3149861159ad258f2cb9491e3 (patch) | |
tree | 2492de6f1528dd44eaa169a5c1555026d9cb75ec /library/vendor/Zend/Validate/File/WordCount.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-a598b28402ead15d3701df32e198513e7b1f299c.tar.xz icingaweb2-a598b28402ead15d3701df32e198513e7b1f299c.zip |
Adding upstream version 2.11.4.upstream/2.11.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | library/vendor/Zend/Validate/File/WordCount.php | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/library/vendor/Zend/Validate/File/WordCount.php b/library/vendor/Zend/Validate/File/WordCount.php new file mode 100644 index 0000000..09b3fd1 --- /dev/null +++ b/library/vendor/Zend/Validate/File/WordCount.php @@ -0,0 +1,99 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Validate + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ + +/** + * @see Zend_Validate_File_Count + */ + +/** + * Validator for counting all words in a file + * + * @category Zend + * @package Zend_Validate + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Validate_File_WordCount extends Zend_Validate_File_Count +{ + /**#@+ + * @const string Error constants + */ + const TOO_MUCH = 'fileWordCountTooMuch'; + const TOO_LESS = 'fileWordCountTooLess'; + const NOT_FOUND = 'fileWordCountNotFound'; + /**#@-*/ + + /** + * @var array Error message templates + */ + protected $_messageTemplates = array( + self::TOO_MUCH => "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 ? + 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; + } +} |