src/Validator/AlphaNumericValidator.php 1 location
|
@@ 21-41 (lines=21) @@
|
| 18 |
|
* |
| 19 |
|
* @author Dmytro Sokil <[email protected]> |
| 20 |
|
*/ |
| 21 |
|
class AlphaNumericValidator extends \Sokil\Mongo\Validator |
| 22 |
|
{ |
| 23 |
|
|
| 24 |
|
public function validateField(Structure $document, $fieldName, array $params) |
| 25 |
|
{ |
| 26 |
|
if (!$document->get($fieldName)) { |
| 27 |
|
return; |
| 28 |
|
} |
| 29 |
|
|
| 30 |
|
if (preg_match('/^\w+$/', $document->get($fieldName))) { |
| 31 |
|
return; |
| 32 |
|
} |
| 33 |
|
|
| 34 |
|
if (!isset($params['message'])) { |
| 35 |
|
$params['message'] = 'Field "' . $fieldName . '" not alpha-numeric in model ' . get_called_class(); |
| 36 |
|
} |
| 37 |
|
|
| 38 |
|
$document->addError($fieldName, $this->getName(), $params['message']); |
| 39 |
|
} |
| 40 |
|
} |
| 41 |
|
|
src/Validator/InValidator.php 1 location
|
@@ 16-37 (lines=22) @@
|
| 13 |
|
|
| 14 |
|
use Sokil\Mongo\Structure; |
| 15 |
|
|
| 16 |
|
class InValidator extends \Sokil\Mongo\Validator |
| 17 |
|
{ |
| 18 |
|
|
| 19 |
|
public function validateField(Structure $document, $fieldName, array $params) |
| 20 |
|
{ |
| 21 |
|
if (!$document->get($fieldName)) { |
| 22 |
|
return; |
| 23 |
|
} |
| 24 |
|
|
| 25 |
|
if (in_array($document->get($fieldName), $params['range'])) { |
| 26 |
|
return; |
| 27 |
|
} |
| 28 |
|
|
| 29 |
|
if (!isset($params['message'])) { |
| 30 |
|
$params['message'] = 'Field "' . $fieldName . '" not in range of allowed values in model ' . get_called_class(); |
| 31 |
|
} |
| 32 |
|
|
| 33 |
|
$document->addError($fieldName, $this->getName(), $params['message']); |
| 34 |
|
} |
| 35 |
|
} |
| 36 |
|
|
src/Validator/NullValidator.php 1 location
|
@@ 16-36 (lines=21) @@
|
| 13 |
|
|
| 14 |
|
use Sokil\Mongo\Structure; |
| 15 |
|
|
| 16 |
|
class NullValidator extends \Sokil\Mongo\Validator |
| 17 |
|
{ |
| 18 |
|
|
| 19 |
|
public function validateField(Structure $document, $fieldName, array $params) |
| 20 |
|
{ |
| 21 |
|
if (!$document->get($fieldName)) { |
| 22 |
|
return; |
| 23 |
|
} |
| 24 |
|
|
| 25 |
|
if (is_null($document->get($fieldName))) { |
| 26 |
|
return; |
| 27 |
|
} |
| 28 |
|
|
| 29 |
|
if (!isset($params['message'])) { |
| 30 |
|
$params['message'] = 'Field "' . $fieldName . '" must be null in model ' . get_called_class(); |
| 31 |
|
} |
| 32 |
|
|
| 33 |
|
$document->addError($fieldName, $this->getName(), $params['message']); |
| 34 |
|
} |
| 35 |
|
} |
| 36 |
|
|
src/Validator/NumericValidator.php 1 location
|
@@ 16-36 (lines=21) @@
|
| 13 |
|
|
| 14 |
|
use Sokil\Mongo\Structure; |
| 15 |
|
|
| 16 |
|
class NumericValidator extends \Sokil\Mongo\Validator |
| 17 |
|
{ |
| 18 |
|
|
| 19 |
|
public function validateField(Structure $document, $fieldName, array $params) |
| 20 |
|
{ |
| 21 |
|
if (!$document->get($fieldName)) { |
| 22 |
|
return; |
| 23 |
|
} |
| 24 |
|
|
| 25 |
|
if (is_numeric($document->get($fieldName))) { |
| 26 |
|
return; |
| 27 |
|
} |
| 28 |
|
|
| 29 |
|
if (!isset($params['message'])) { |
| 30 |
|
$params['message'] = 'Field "' . $fieldName . '" not numeric in model ' . get_called_class(); |
| 31 |
|
} |
| 32 |
|
|
| 33 |
|
$document->addError($fieldName, $this->getName(), $params['message']); |
| 34 |
|
} |
| 35 |
|
} |
| 36 |
|
|