1: <?php
2: 3: 4: 5: 6: 7:
8:
9: namespace Wei\Validator;
10:
11: 12: 13: 14: 15:
16: class MinLength extends Length
17: {
18: protected $tooShortMessage = '%name% must have a length greater than %min%';
19:
20: protected $tooFewMessage = '%name% must contain at least %min% item(s)';
21:
22: protected $min;
23:
24: 25: 26:
27: public function __invoke($input, $min = null, $__ = null)
28: {
29: $min && $this->storeOption('min', $min);
30:
31: return $this->isValid($input);
32: }
33:
34: 35: 36:
37: protected function doValidate($input)
38: {
39: if (false === ($len = $this->getLength($input))) {
40: $this->addError('notDetected');
41: return false;
42: }
43:
44: if ($this->min > $len) {
45: $this->addError(is_scalar($input) ? 'tooShort' : 'tooFew');
46: return false;
47: }
48:
49: return true;
50: }
51: }
52: