Development

/branches/1.4/lib/validator/sfValidatorDecorator.class.php

You must first sign up to be able to contribute.

root/branches/1.4/lib/validator/sfValidatorDecorator.class.php

Revision 7902, 3.2 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
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  * sfValidatorDecorator decorates another validator.
13  *
14  * This validator has exactly the same behavior as the Decorator validator.
15  *
16  * The options and messages are proxied from the decorated validator.
17  *
18  * @package    symfony
19  * @subpackage validator
20  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
21  * @version    SVN: $Id$
22  */
23 abstract class sfValidatorDecorator extends sfValidatorBase
24 {
25   protected
26     $validator = null;
27
28   /**
29    * @see sfValidatorBase
30    */
31   public function __construct($options = array(), $messages = array())
32   {
33     $this->validator = $this->getValidator();
34
35     if (!$this->validator instanceof sfValidatorBase)
36     {
37       throw new RuntimeException('The getValidator() method must return a sfValidatorBase instance.');
38     }
39
40     foreach ($options as $key => $value)
41     {
42       $this->validator->setOption($key, $value);
43     }
44
45     foreach ($messages as $key => $value)
46     {
47       $this->validator->setMessage($key, $value);
48     }
49   }
50
51   /**
52    * Returns the decorated validator.
53    *
54    * Every subclass must implement this method.
55    *
56    * @return sfValidatorBase A sfValidatorBase instance
57    */
58   abstract protected function getValidator();
59
60   /**
61    * @see sfValidatorBase
62    */
63   public function clean($value)
64   {
65     return $this->doClean($value);
66   }
67
68   /**
69    * @see sfValidatorBase
70    */
71   protected function doClean($value)
72   {
73     return $this->validator->clean($value);
74   }
75
76   /**
77    * @see sfValidatorBase
78    */
79   public function getMessage($name)
80   {
81     return $this->validator->getMessage($name);
82   }
83
84   /**
85    * @see sfValidatorBase
86    */
87   public function setMessage($name, $value)
88   {
89     $this->validator->setMessage($name, $value);
90   }
91
92   /**
93    * @see sfValidatorBase
94    */
95   public function getMessages()
96   {
97     return $this->validator->getMessages();
98   }
99
100   /**
101    * @see sfValidatorBase
102    */
103   public function setMessages($values)
104   {
105     return $this->validator->setMessages($values);
106   }
107
108   /**
109    * @see sfValidatorBase
110    */
111   public function getOption($name)
112   {
113     return $this->validator->getOption($name);
114   }
115
116   /**
117    * @see sfValidatorBase
118    */
119   public function setOption($name, $value)
120   {
121     $this->validator->setOption($name, $value);
122   }
123
124   /**
125    * @see sfValidatorBase
126    */
127   public function hasOption($name)
128   {
129     return $this->validator->hasOption($name);
130   }
131
132   /**
133    * @see sfValidatorBase
134    */
135   public function getOptions()
136   {
137     return $this->validator->getOptions();
138   }
139
140   /**
141    * @see sfValidatorBase
142    */
143   public function setOptions($values)
144   {
145     $this->validator->setOptions($values);
146   }
147
148   /**
149    * @see sfValidatorBase
150    */
151   public function asString($indent = 0)
152   {
153     return $this->validator->asString($indent);
154   }
155
156   /**
157    * @see sfValidatorBase
158    */
159   public function getDefaultOptions()
160   {
161     return $this->validator->getDefaultOptions();
162   }
163
164   /**
165    * @see sfValidatorBase
166    */
167   public function getDefaultMessages()
168   {
169     return $this->validator->getDefaultMessages();
170   }
171 }
172
Note: See TracBrowser for help on using the browser.