| @@ 16-38 (lines=23) @@ | ||
| 13 | ||
| 14 | use Sokil\Mongo\Structure; |
|
| 15 | ||
| 16 | class GreaterValidator extends \Sokil\Mongo\Validator |
|
| 17 | { |
|
| 18 | ||
| 19 | public function validateField(Structure $document, $fieldName, array $params) |
|
| 20 | { |
|
| 21 | $value = $document->get($fieldName); |
|
| 22 | if (!$value) { |
|
| 23 | return; |
|
| 24 | } |
|
| 25 | ||
| 26 | if (!isset($params['than'])) { |
|
| 27 | throw new Exception('Maximum value not specified'); |
|
| 28 | } |
|
| 29 | ||
| 30 | if ($value <= $params['than']) { |
|
| 31 | if (empty($params['message'])) { |
|
| 32 | $params['message'] = 'Field "' . $fieldName . '" must be greater than specified value in ' . get_called_class(); |
|
| 33 | } |
|
| 34 | $document->addError($fieldName, $this->getName(), $params['message']); |
|
| 35 | } |
|
| 36 | } |
|
| 37 | } |
|
| 38 | ||
| @@ 16-38 (lines=23) @@ | ||
| 13 | ||
| 14 | use Sokil\Mongo\Structure; |
|
| 15 | ||
| 16 | class LessValidator extends \Sokil\Mongo\Validator |
|
| 17 | { |
|
| 18 | ||
| 19 | public function validateField(Structure $document, $fieldName, array $params) |
|
| 20 | { |
|
| 21 | $value = $document->get($fieldName); |
|
| 22 | if (!$value) { |
|
| 23 | return; |
|
| 24 | } |
|
| 25 | ||
| 26 | if (!isset($params['than'])) { |
|
| 27 | throw new Exception('Maximum value not specified'); |
|
| 28 | } |
|
| 29 | ||
| 30 | if ($value >= $params['than']) { |
|
| 31 | if (empty($params['message'])) { |
|
| 32 | $params['message'] = 'Field "' . $fieldName . '" must be less than specified value in ' . get_called_class(); |
|
| 33 | } |
|
| 34 | $document->addError($fieldName, $this->getName(), $params['message']); |
|
| 35 | } |
|
| 36 | } |
|
| 37 | } |
|
| 38 | ||