| @@ 30-46 (lines=17) @@ | ||
| 27 | $length = mb_strlen($value); |
|
| 28 | ||
| 29 | // check if field is of specified length |
|
| 30 | if (isset($params['is'])) { |
|
| 31 | if ($length === $params['is']) { |
|
| 32 | return; |
|
| 33 | } |
|
| 34 | ||
| 35 | if (!isset($params['message'])) { |
|
| 36 | $params['message'] = sprintf( |
|
| 37 | 'Field "%s" length not equal to %s in model %s', |
|
| 38 | $fieldName, |
|
| 39 | $params['is'], |
|
| 40 | get_called_class() |
|
| 41 | ); |
|
| 42 | } |
|
| 43 | ||
| 44 | $document->addError($fieldName, $this->getName(), $params['message']); |
|
| 45 | return; |
|
| 46 | } |
|
| 47 | ||
| 48 | // check if fied is shorter than required |
|
| 49 | if (isset($params['min'])) { |
|
| @@ 49-63 (lines=15) @@ | ||
| 46 | } |
|
| 47 | ||
| 48 | // check if fied is shorter than required |
|
| 49 | if (isset($params['min'])) { |
|
| 50 | if ($length < $params['min']) { |
|
| 51 | if (!isset($params['messageTooShort'])) { |
|
| 52 | $params['messageTooShort'] = sprintf( |
|
| 53 | 'Field "%s" length is shorter than %s in model %s', |
|
| 54 | $fieldName, |
|
| 55 | $params['min'], |
|
| 56 | get_called_class() |
|
| 57 | ); |
|
| 58 | } |
|
| 59 | ||
| 60 | $document->addError($fieldName, $this->getName(), $params['messageTooShort']); |
|
| 61 | return; |
|
| 62 | } |
|
| 63 | } |
|
| 64 | ||
| 65 | // check if fied is longer than required |
|
| 66 | if (isset($params['max'])) { |
|
| @@ 66-80 (lines=15) @@ | ||
| 63 | } |
|
| 64 | ||
| 65 | // check if fied is longer than required |
|
| 66 | if (isset($params['max'])) { |
|
| 67 | if ($length > $params['max']) { |
|
| 68 | if (!isset($params['messageTooLong'])) { |
|
| 69 | $params['messageTooLong'] = sprintf( |
|
| 70 | 'Field "%s" length is longer than %s in model %s', |
|
| 71 | $fieldName, |
|
| 72 | $params['max'], |
|
| 73 | get_called_class() |
|
| 74 | ); |
|
| 75 | } |
|
| 76 | ||
| 77 | $document->addError($fieldName, $this->getName(), $params['messageTooLong']); |
|
| 78 | return; |
|
| 79 | } |
|
| 80 | } |
|
| 81 | } |
|
| 82 | } |
|
| 83 | ||