Development

/branches/1.0/lib/validator/sfCompareValidator.class.php

You must first sign up to be able to contribute.

root/branches/1.0/lib/validator/sfCompareValidator.class.php

Revision 3233, 1.6 kB (checked in by fabien, 8 years ago)

updated phpdoc for lib/validator classes (based on a patch from Rafael George)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Rev Date
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) 2004-2006 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  * sfCompareValidator checks the equality of two different request parameters.
13  *
14  * passwordValidator:
15  *   class:            sfCompareValidator
16  *   param:
17  *     check:          password2
18  *     compare_error:  The passwords you entered do not match. Please try again.
19  *
20  * @package    symfony
21  * @subpackage validator
22  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
23  * @version    SVN: $Id$
24  */
25 class sfCompareValidator extends sfValidator
26 {
27   /**
28    * Executes this validator.
29    *
30    * @param mixed A file or parameter value/array
31    * @param error An error message reference
32    *
33    * @return bool true, if this validator executes successfully, otherwise false
34    */
35   public function execute(&$value, &$error)
36   {
37     $check_param = $this->getParameterHolder()->get('check');
38     $check_value = $this->getContext()->getRequest()->getParameter($check_param);
39
40     if ($value !== $check_value)
41     {
42       $error = $this->getParameterHolder()->get('compare_error');
43       return false;
44     }
45
46     return true;
47   }
48
49   public function initialize($context, $parameters = null)
50   {
51     // initialize parent
52     parent::initialize($context);
53
54     // set defaults
55     $this->getParameterHolder()->set('compare_error', 'Invalid input');
56
57     $this->getParameterHolder()->add($parameters);
58
59     return true;
60   }
61 }
62
Note: See TracBrowser for help on using the browser.