Development

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

You must first sign up to be able to contribute.

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

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

updated Sean Kerr email address

  • 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  * sfValidator 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    * Executes this validator.
29    *
30    * @param mixed A file or parameter value/array
31    * @param string An error message reference
32    *
33    * @return bool true, if this validator executes successfully, otherwise false
34    */
35   abstract function execute(&$value, &$error);
36
37   /**
38    * Retrieves the current application context.
39    *
40    * @return sfContext The current sfContext instance
41    */
42   public final function getContext()
43   {
44     return $this->context;
45   }
46
47   /**
48    * Initializes this validator.
49    *
50    * @param sfContext The current application context
51    * @param array   An associative array of initialization parameters
52    *
53    * @return bool true, if initialization completes successfully, otherwise false
54    */
55   public function initialize($context, $parameters = array())
56   {
57     $this->context = $context;
58
59     $this->parameterHolder = new sfParameterHolder();
60     $this->parameterHolder->add($parameters);
61
62     return true;
63   }
64
65   /**
66    * Retrieves the parameters from the validator.
67    *
68    * @return sfParameterHolder List of parameters
69    */
70   public function getParameterHolder()
71   {
72     return $this->parameterHolder;
73   }
74
75   /**
76    * Retrieves a parameter from the validator.
77    *
78    * @param string Parameter name
79    * @param mixed A default parameter value
80    * @param string A parameter namespace
81    *
82    * @return mixed A parameter value
83    */
84   public function getParameter($name, $default = null, $ns = null)
85   {
86     return $this->parameterHolder->get($name, $default, $ns);
87   }
88
89   /**
90    * Indicates whether or not a parameter exist for the validator.
91    *
92    * @param string A parameter name
93    * @param string A parameter namespace
94    *
95    * @return boolean true, if parameter exists, otherwise false
96    */
97   public function hasParameter($name, $ns = null)
98   {
99     return $this->parameterHolder->has($name, $ns);
100   }
101
102   /**
103    * Sets a parameter for the validator.
104    *
105    * @param string A parameter name
106    * @param mixed A parameter value
107    * @param string A parameter namespace
108    */
109   public function setParameter($name, $value, $ns = null)
110   {
111     $this->parameterHolder->set($name, $value, $ns);
112   }
113 }
114
Note: See TracBrowser for help on using the browser.