Development

/branches/1.1/lib/validator/sfValidatorSchemaFilter.class.php

You must first sign up to be able to contribute.

root/branches/1.1/lib/validator/sfValidatorSchemaFilter.class.php

Revision 11003, 1.9 kB (checked in by fabien, 6 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  * This file is part of the symfony package.
5  * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * sfValidatorSchemaFilter executes non schema validator on a schema input value.
13  *
14  * @package    symfony
15  * @subpackage validator
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
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
Note: See TracBrowser for help on using the browser.