|
Revision 22018, 1.9 kB
(checked in by fabien, 3 years ago)
|
[1.2, 1.3] fixed number validators default min/max error messages (closes #7035, #6485)
|
- Property svn:mime-type set to
text/x-php
- Property svn:eol-style set to
native
- Property svn:keywords set to
Id
|
| Line | |
|---|
| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfValidatorInteger extends sfValidatorBase |
|---|
| 20 |
{ |
|---|
| 21 |
|
|---|
| 22 |
* Configures the current validator. |
|---|
| 23 |
* |
|---|
| 24 |
* Available options: |
|---|
| 25 |
* |
|---|
| 26 |
* * max: The maximum value allowed |
|---|
| 27 |
* * min: The minimum value allowed |
|---|
| 28 |
* |
|---|
| 29 |
* Available error codes: |
|---|
| 30 |
* |
|---|
| 31 |
* * max |
|---|
| 32 |
* * min |
|---|
| 33 |
* |
|---|
| 34 |
* @param array $options An array of options |
|---|
| 35 |
* @param array $messages An array of error messages |
|---|
| 36 |
* |
|---|
| 37 |
* @see sfValidatorBase |
|---|
| 38 |
*/ |
|---|
| 39 |
protected function configure($options = array(), $messages = array()) |
|---|
| 40 |
{ |
|---|
| 41 |
$this->addMessage('max', '"%value%" must be at most %max%.'); |
|---|
| 42 |
$this->addMessage('min', '"%value%" must be at least %min%.'); |
|---|
| 43 |
|
|---|
| 44 |
$this->addOption('min'); |
|---|
| 45 |
$this->addOption('max'); |
|---|
| 46 |
|
|---|
| 47 |
$this->setMessage('invalid', '"%value%" is not an integer.'); |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
* @see sfValidatorBase |
|---|
| 52 |
*/ |
|---|
| 53 |
protected function doClean($value) |
|---|
| 54 |
{ |
|---|
| 55 |
$clean = intval($value); |
|---|
| 56 |
|
|---|
| 57 |
if (strval($clean) != $value) |
|---|
| 58 |
{ |
|---|
| 59 |
throw new sfValidatorError($this, 'invalid', array('value' => $value)); |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
if ($this->hasOption('max') && $clean > $this->getOption('max')) |
|---|
| 63 |
{ |
|---|
| 64 |
throw new sfValidatorError($this, 'max', array('value' => $value, 'max' => $this->getOption('max'))); |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
if ($this->hasOption('min') && $clean < $this->getOption('min')) |
|---|
| 68 |
{ |
|---|
| 69 |
throw new sfValidatorError($this, 'min', array('value' => $value, 'min' => $this->getOption('min'))); |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
return $clean; |
|---|
| 73 |
} |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|