Development

/branches/1.2/lib/plugins/sfCompat10Plugin/lib/validator/sfValidator.class.php

You must first sign up to be able to contribute.

root/branches/1.2/lib/plugins/sfCompat10Plugin/lib/validator/sfValidator.class.php

Revision 7902, 2.8 kB (checked in by fabien, 6 years ago)

rename sfValidatorBase to sfValidator in sfCompat10Plugin and renamed the new sfValidator class to sfValidatorBase (closes #3103)

  • 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  * (c) 2004-2006 Sean Kerr <sean@code-box.org>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 /**
13  * sfValidatorBase allows you to apply constraints to user entered parameters.
14  *
15  * @package    symfony
16  * @subpackage validator
17  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
18  * @author     Sean Kerr <sean@code-box.org>
19  * @version    SVN: $Id$
20  */
21 abstract class sfValidator
22 {
23   protected
24     $parameterHolder = null,
25     $context         = null;
26
27   /**
28    * Class constructor.
29    *
30    * @see initialize()
31    */
32   public function __construct($context, $parameters = array())
33   {
34     $this->initialize($context, $parameters);
35   }
36
37   /**
38    * Initializes this validator.
39    *
40    * @param sfContext The current application context
41    * @param array   An associative array of initialization parameters
42    *
43    * @return bool true, if initialization completes successfully, otherwise false
44    */
45   public function initialize($context, $parameters = array())
46   {
47     $this->context = $context;
48
49     $this->parameterHolder = new sfParameterHolder();
50     $this->parameterHolder->add($parameters);
51
52     return true;
53   }
54
55   /**
56    * Executes this validator.
57    *
58    * @param mixed A file or parameter value/array
59    * @param string An error message reference
60    *
61    * @return bool true, if this validator executes successfully, otherwise false
62    */
63   abstract function execute(&$value, &$error);
64
65   /**
66    * Retrieves the current application context.
67    *
68    * @return sfContext The current sfContext instance
69    */
70   public final function getContext()
71   {
72     return $this->context;
73   }
74
75   /**
76    * Retrieves the parameters from the validator.
77    *
78    * @return sfParameterHolder List of parameters
79    */
80   public function getParameterHolder()
81   {
82     return $this->parameterHolder;
83   }
84
85   /**
86    * Retrieves a parameter from the validator.
87    *
88    * @param string Parameter name
89    * @param mixed A default parameter value
90    *
91    * @return mixed A parameter value
92    */
93   public function getParameter($name, $default = null)
94   {
95     return $this->parameterHolder->get($name, $default);
96   }
97
98   /**
99    * Indicates whether or not a parameter exist for the validator.
100    *
101    * @param string A parameter name
102    *
103    * @return boolean true, if parameter exists, otherwise false
104    */
105   public function hasParameter($name)
106   {
107     return $this->parameterHolder->has($name);
108   }
109
110   /**
111    * Sets a parameter for the validator.
112    *
113    * @param string A parameter name
114    * @param mixed A parameter value
115    */
116   public function setParameter($name, $value)
117   {
118     $this->parameterHolder->set($name, $value);
119   }
120 }
121
Note: See TracBrowser for help on using the browser.