root/trunk/lib/form/validator/sfValidatorBlacklist.class.php

Revision 52, 1.4 kB (checked in by nperriault, 2 years ago)

Enhanced registration form, added CSRF protection by default

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  * sfValidatorBlacklist validates than the value is not one of the expected values.
13  *
14  * @package    symfony
15  * @subpackage validator
16  * @author     Nicolas Perriault <nicolas.perriault@symfony-project.com>
17  * @version    SVN: $Id: sfValidatorChoice.class.php 9048 2008-05-19 09:11:23Z FabianLange $
18  */
19 class sfValidatorBlacklist extends sfValidatorChoice
20 {
21   /**
22    * Configures the current validator.
23    *
24    * Available options:
25    *
26    *  * choices: An array of forbidden values (required)
27    *
28    * @param array $options    An array of options
29    * @param array $messages   An array of error messages
30    *
31    * @see sfValidatorBase
32    */
33   protected function configure($options = array(), $messages = array())
34   {
35     $this->addRequiredOption('choices');
36   }
37
38   /**
39    * @see sfValidatorBase
40    */
41   protected function doClean($value)
42   {
43     $choices = $this->getOption('choices');
44     if ($choices instanceof sfCallable)
45     {
46       $choices = $choices->call();
47     }
48
49     if (in_array($value, $choices))
50     {
51       throw new sfValidatorError($this, 'invalid', array('value' => $value));
52     }
53
54     return $value;
55   }
56 }
57
Note: See TracBrowser for help on using the browser.