1: <?php
2: /**
3: * Wei Framework
4: *
5: * @copyright Copyright (c) 2008-2013 Twin Huang
6: * @license http://opensource.org/licenses/mit-license.php MIT License
7: */
8:
9: namespace Wei\Validator;
10:
11: /**
12: * Check if the input is between the specified minimum and maximum value
13: *
14: * @author Twin Huang <twinhuang@qq.com>
15: */
16: class Between extends BaseValidator
17: {
18: protected $betweenMessage = '%name% must between %min% and %max%';
19:
20: protected $negativeMessage = '%name% must not between %min% and %max%';
21:
22: protected $min;
23:
24: protected $max;
25:
26: /**
27: * {@inheritdoc}
28: */
29: public function __invoke($input, $min = null, $max = null)
30: {
31: // Allows not numeric parameter like 2000-01-01, 10:03, etc
32: if ($min && $max) {
33: $this->storeOption('min', $min);
34: $this->storeOption('max', $max);
35: }
36:
37: return $this->isValid($input);
38: }
39:
40: /**
41: * {@inheritdoc}
42: */
43: protected function doValidate($input)
44: {
45: if ($this->min > $input || $this->max < $input) {
46: $this->addError('between');
47: return false;
48: }
49: return true;
50: }
51: }
52: