Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
WordCount.php
Go to the documentation of this file.
1 <?php
25 #require_once 'Zend/Validate/File/Count.php';
26 
36 {
40  const TOO_MUCH = 'fileWordCountTooMuch';
41  const TOO_LESS = 'fileWordCountTooLess';
42  const NOT_FOUND = 'fileWordCountNotFound';
48  protected $_messageTemplates = array(
49  self::TOO_MUCH => "Too much words, maximum '%max%' are allowed but '%count%' were counted",
50  self::TOO_LESS => "Too less words, minimum '%min%' are expected but '%count%' were counted",
51  self::NOT_FOUND => "File '%value%' is not readable or does not exist",
52  );
53 
64  public function isValid($value, $file = null)
65  {
66  // Is file readable ?
67  #require_once 'Zend/Loader.php';
69  return $this->_throw($file, self::NOT_FOUND);
70  }
71 
73  $this->_count = str_word_count($content);
74  if (($this->_max !== null) && ($this->_count > $this->_max)) {
75  return $this->_throw($file, self::TOO_MUCH);
76  }
77 
78  if (($this->_min !== null) && ($this->_count < $this->_min)) {
79  return $this->_throw($file, self::TOO_LESS);
80  }
81 
82  return true;
83  }
84 
92  protected function _throw($file, $errorType)
93  {
94  if ($file !== null) {
95  $this->_value = $file['name'];
96  }
97 
98  $this->_error($errorType);
99  return false;
100  }
101 }
isValid($value, $file=null)
Definition: WordCount.php:64
_throw($file, $errorType)
Definition: WordCount.php:92
_error($messageKey, $value=null)
Definition: Abstract.php:284
static isReadable($filename)
Definition: Loader.php:162
$value
Definition: gender.phtml:16