| @@ 22-89 (lines=68) @@ | ||
| 19 | * @author Fuel Development Team |
|
| 20 | * @since 2.0 |
|
| 21 | */ |
|
| 22 | class NumericMax extends AbstractRule |
|
| 23 | { |
|
| 24 | ||
| 25 | /** |
|
| 26 | * Contains the rule failure message |
|
| 27 | * |
|
| 28 | * @var string |
|
| 29 | */ |
|
| 30 | protected $message = 'The field is not equal to or less than the specified value.'; |
|
| 31 | ||
| 32 | /** |
|
| 33 | * @param mixed $value Value to validate |
|
| 34 | * @param string $field Unused by this rule |
|
| 35 | * @param array $allFields Unused by this rule |
|
| 36 | * |
|
| 37 | * @return bool |
|
| 38 | * |
|
| 39 | * @since 2.0 |
|
| 40 | */ |
|
| 41 | public function validate($value, $field = null, $allFields = null) |
|
| 42 | { |
|
| 43 | $max = $this->getParameter(); |
|
| 44 | ||
| 45 | if ($max === null or ! is_numeric($value)) |
|
| 46 | { |
|
| 47 | return false; |
|
| 48 | } |
|
| 49 | ||
| 50 | return $value <= $max; |
|
| 51 | } |
|
| 52 | ||
| 53 | /** |
|
| 54 | * Sets the value to check against |
|
| 55 | * |
|
| 56 | * @param string $params If an array the first value will be used |
|
| 57 | * |
|
| 58 | * @return $this |
|
| 59 | * |
|
| 60 | * @since 2.0 |
|
| 61 | */ |
|
| 62 | public function setParameter($params) |
|
| 63 | { |
|
| 64 | // Ensure we have only a single thing to match against |
|
| 65 | if (is_array($params)) |
|
| 66 | { |
|
| 67 | $params = array_shift($params); |
|
| 68 | } |
|
| 69 | ||
| 70 | return parent::setParameter($params); |
|
| 71 | } |
|
| 72 | ||
| 73 | /** |
|
| 74 | * Returns |
|
| 75 | * |
|
| 76 | * array( |
|
| 77 | * 'maxValue' => <target value> |
|
| 78 | * ); |
|
| 79 | * |
|
| 80 | * @return string[] |
|
| 81 | */ |
|
| 82 | public function getMessageParameters() |
|
| 83 | { |
|
| 84 | return array( |
|
| 85 | 'maxValue' => $this->getParameter(), |
|
| 86 | ); |
|
| 87 | } |
|
| 88 | ||
| 89 | } |
|
| 90 | ||
| @@ 22-89 (lines=68) @@ | ||
| 19 | * @author Fuel Development Team |
|
| 20 | * @since 2.0 |
|
| 21 | */ |
|
| 22 | class NumericMin extends AbstractRule |
|
| 23 | { |
|
| 24 | ||
| 25 | /** |
|
| 26 | * Contains the rule failure message |
|
| 27 | * |
|
| 28 | * @var string |
|
| 29 | */ |
|
| 30 | protected $message = 'The field is not equal to or greater than the specified value.'; |
|
| 31 | ||
| 32 | /** |
|
| 33 | * @param mixed $value Value to validate |
|
| 34 | * @param string $field Unused by this rule |
|
| 35 | * @param array $allFields Unused by this rule |
|
| 36 | * |
|
| 37 | * @return bool |
|
| 38 | * |
|
| 39 | * @since 2.0 |
|
| 40 | */ |
|
| 41 | public function validate($value, $field = null, $allFields = null) |
|
| 42 | { |
|
| 43 | $min = $this->getParameter(); |
|
| 44 | ||
| 45 | if ($min === null or ! is_numeric($value)) |
|
| 46 | { |
|
| 47 | return false; |
|
| 48 | } |
|
| 49 | ||
| 50 | return $value >= $min; |
|
| 51 | } |
|
| 52 | ||
| 53 | /** |
|
| 54 | * Sets the value to check against |
|
| 55 | * |
|
| 56 | * @param string $params If an array the first value will be used |
|
| 57 | * |
|
| 58 | * @return $this |
|
| 59 | * |
|
| 60 | * @since 2.0 |
|
| 61 | */ |
|
| 62 | public function setParameter($params) |
|
| 63 | { |
|
| 64 | // Ensure we have only a single thing to match against |
|
| 65 | if (is_array($params)) |
|
| 66 | { |
|
| 67 | $params = array_shift($params); |
|
| 68 | } |
|
| 69 | ||
| 70 | return parent::setParameter($params); |
|
| 71 | } |
|
| 72 | ||
| 73 | /** |
|
| 74 | * Returns |
|
| 75 | * |
|
| 76 | * array( |
|
| 77 | * 'minValue' => <target value> |
|
| 78 | * ); |
|
| 79 | * |
|
| 80 | * @return string[] |
|
| 81 | */ |
|
| 82 | public function getMessageParameters() |
|
| 83 | { |
|
| 84 | return array( |
|
| 85 | 'minValue' => $this->getParameter(), |
|
| 86 | ); |
|
| 87 | } |
|
| 88 | ||
| 89 | } |
|
| 90 | ||
| @@ 23-90 (lines=68) @@ | ||
| 20 | * |
|
| 21 | * @since 2.0 |
|
| 22 | */ |
|
| 23 | class Regex extends AbstractRule |
|
| 24 | { |
|
| 25 | ||
| 26 | /** |
|
| 27 | * Contains the rule failure message |
|
| 28 | * |
|
| 29 | * @var string |
|
| 30 | */ |
|
| 31 | protected $message = 'The field does not match the given pattern.'; |
|
| 32 | ||
| 33 | /** |
|
| 34 | * @param mixed $value Value to validate |
|
| 35 | * @param string $field Unused by this rule |
|
| 36 | * @param array $allFields Unused by this rule |
|
| 37 | * |
|
| 38 | * @return bool |
|
| 39 | * |
|
| 40 | * @since 2.0 |
|
| 41 | */ |
|
| 42 | public function validate($value, $field = null, $allFields = null) |
|
| 43 | { |
|
| 44 | $regex = $this->getParameter(); |
|
| 45 | ||
| 46 | if ( ! is_string($value) or $regex === null) |
|
| 47 | { |
|
| 48 | return false; |
|
| 49 | } |
|
| 50 | ||
| 51 | return preg_match($regex, $value) == true; |
|
| 52 | } |
|
| 53 | ||
| 54 | /** |
|
| 55 | * Sets the value to check against |
|
| 56 | * |
|
| 57 | * @param string $params If an array the first value will be used |
|
| 58 | * |
|
| 59 | * @return $this |
|
| 60 | * |
|
| 61 | * @since 2.0 |
|
| 62 | */ |
|
| 63 | public function setParameter($params) |
|
| 64 | { |
|
| 65 | // Ensure we have only a single thing to match against |
|
| 66 | if (is_array($params)) |
|
| 67 | { |
|
| 68 | $params = array_shift($params); |
|
| 69 | } |
|
| 70 | ||
| 71 | return parent::setParameter($params); |
|
| 72 | } |
|
| 73 | ||
| 74 | /** |
|
| 75 | * Returns |
|
| 76 | * |
|
| 77 | * array( |
|
| 78 | * 'pattern' => <Regex used for matching> |
|
| 79 | * ); |
|
| 80 | * |
|
| 81 | * @return string[] |
|
| 82 | */ |
|
| 83 | public function getMessageParameters() |
|
| 84 | { |
|
| 85 | return array( |
|
| 86 | 'pattern' => $this->getParameter(), |
|
| 87 | ); |
|
| 88 | } |
|
| 89 | ||
| 90 | } |
|
| 91 | ||