|
Revision 11003, 1.9 kB
(checked in by fabien, 5 years ago)
|
[1.1, 1.2] fixed sfValidatorSchemaFilter not throwing an error bound to the filtered field (closes #4233)
|
- 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 sfValidatorSchemaFilter extends sfValidatorSchema |
|---|
| 20 |
{ |
|---|
| 21 |
|
|---|
| 22 |
* Constructor. |
|---|
| 23 |
* |
|---|
| 24 |
* @param string $field The field name |
|---|
| 25 |
* @param sfValidatorBase $validator The validator |
|---|
| 26 |
* @param array $options An array of options |
|---|
| 27 |
* @param array $messages An array of error messages |
|---|
| 28 |
* |
|---|
| 29 |
* @see sfValidatorBase |
|---|
| 30 |
*/ |
|---|
| 31 |
public function __construct($field, sfValidatorBase $validator, $options = array(), $messages = array()) |
|---|
| 32 |
{ |
|---|
| 33 |
$this->addOption('field', $field); |
|---|
| 34 |
$this->addOption('validator', $validator); |
|---|
| 35 |
|
|---|
| 36 |
parent::__construct(null, $options, $messages); |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
* @see sfValidatorBase |
|---|
| 41 |
*/ |
|---|
| 42 |
protected function doClean($values) |
|---|
| 43 |
{ |
|---|
| 44 |
if (is_null($values)) |
|---|
| 45 |
{ |
|---|
| 46 |
$values = array(); |
|---|
| 47 |
} |
|---|
| 48 |
|
|---|
| 49 |
if (!is_array($values)) |
|---|
| 50 |
{ |
|---|
| 51 |
throw new InvalidArgumentException('You must pass an array parameter to the clean() method'); |
|---|
| 52 |
} |
|---|
| 53 |
|
|---|
| 54 |
$value = isset($values[$this->getOption('field')]) ? $values[$this->getOption('field')] : null; |
|---|
| 55 |
|
|---|
| 56 |
try |
|---|
| 57 |
{ |
|---|
| 58 |
$values[$this->getOption('field')] = $this->getOption('validator')->clean($value); |
|---|
| 59 |
} |
|---|
| 60 |
catch (sfValidatorError $error) |
|---|
| 61 |
{ |
|---|
| 62 |
throw new sfValidatorErrorSchema($this, array($this->getOption('field') => $error)); |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
return $values; |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
* @see sfValidatorBase |
|---|
| 70 |
*/ |
|---|
| 71 |
public function asString($indent = 0) |
|---|
| 72 |
{ |
|---|
| 73 |
return sprintf('%s%s:%s', str_repeat(' ', $indent), $this->getOption('field'), $this->getOption('validator')->asString(0)); |
|---|
| 74 |
} |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|