We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| 1 | <?php |
||
| 17 | class Zend extends AbstractRule |
||
| 18 | { |
||
| 19 | protected $messages = []; |
||
| 20 | protected $zendValidator; |
||
| 21 | |||
| 22 | 9 | public function __construct($validator, $params = []) |
|
| 23 | { |
||
| 24 | 9 | if (is_object($validator)) { |
|
| 25 | 2 | return $this->zendValidator = $validator; |
|
|
|
|||
| 26 | } |
||
| 27 | |||
| 28 | 7 | if (!is_string($validator)) { |
|
| 29 | throw new ComponentException('Invalid Validator Construct'); |
||
| 30 | } |
||
| 31 | |||
| 32 | 7 | if (false === stripos($validator, 'Zend')) { |
|
| 33 | 6 | $validator = "Zend\\Validator\\{$validator}"; |
|
| 34 | } else { |
||
| 35 | 1 | $validator = "\\{$validator}"; |
|
| 36 | } |
||
| 37 | |||
| 38 | 7 | $zendMirror = new ReflectionClass($validator); |
|
| 39 | |||
| 40 | 7 | if ($zendMirror->hasMethod('__construct')) { |
|
| 41 | 7 | $this->zendValidator = $zendMirror->newInstanceArgs($params); |
|
| 42 | } else { |
||
| 43 | $this->zendValidator = $zendMirror->newInstance(); |
||
| 44 | } |
||
| 45 | 7 | } |
|
| 46 | |||
| 47 | 3 | public function assert($input) |
|
| 48 | { |
||
| 49 | 3 | $validator = clone $this->zendValidator; |
|
| 50 | |||
| 51 | 3 | if ($validator->isValid($input)) { |
|
| 52 | 1 | return true; |
|
| 53 | } |
||
| 54 | |||
| 55 | 2 | $exceptions = []; |
|
| 56 | 2 | foreach ($validator->getMessages() as $m) { |
|
| 57 | 2 | $exceptions[] = $this->reportError($m, get_object_vars($this)); |
|
| 58 | } |
||
| 59 | |||
| 60 | 2 | throw $this->reportError($input)->setRelated($exceptions); |
|
| 61 | } |
||
| 62 | |||
| 63 | 3 | public function validate($input) |
|
| 69 | } |
||
| 70 |