1 | <?php |
||
21 | abstract class AbstractRule implements RuleInterface |
||
22 | { |
||
23 | /** |
||
24 | * Message for error output |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $description = 'is invalid'; |
||
28 | |||
29 | /** |
||
30 | * @inheritdoc |
||
31 | */ |
||
32 | 7 | public function assert($input) : void |
|
33 | { |
||
34 | 7 | if (!$this->validate($input)) { |
|
35 | 7 | throw new ValidatorException($this->description); |
|
36 | } |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * @inheritdoc |
||
41 | */ |
||
42 | 14 | public function __invoke($input) : bool |
|
43 | { |
||
44 | 14 | return $this->validate($input); |
|
45 | } |
||
46 | |||
47 | /** |
||
48 | * @inheritdoc |
||
49 | */ |
||
50 | 440 | public function __toString() : string |
|
54 | |||
55 | /** |
||
56 | * @inheritdoc |
||
57 | */ |
||
58 | 197 | public function getDescription() : string |
|
62 | |||
63 | /** |
||
64 | * @inheritdoc |
||
65 | */ |
||
66 | 4 | public function setDescription(string $description) : RuleInterface |
|
71 | } |
||
72 |