1: <?php
2: /**
3: * Wei Framework
4: *
5: * @copyright Copyright (c) 2008-2015 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 blank
13: *
14: * @author Twin Huang <twinhuang@qq.com>
15: */
16: class Blank extends BaseValidator
17: {
18: protected $blankMessage = '%name% must be blank';
19:
20: protected $negativeMessage = '%name% must not be blank';
21:
22: /**
23: * The invalid variable values
24: *
25: * @var array
26: */
27: protected $invalid = array(null, '', false, array());
28:
29: /**
30: * {@inheritdoc}
31: */
32: protected function doValidate($input)
33: {
34: if (
35: in_array($input, $this->invalid, true)
36: || ($this->isString($input) && '' === trim($input))
37: ) {
38: return true;
39: } else {
40: $this->addError('blank');
41: return false;
42: }
43: }
44: }
45: