Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 49 lines (46 sloc) 1.541 kB
55bdd95 removed carriage returns from files.
qiang.xue authored
1 <?php
2 /**
3 * CFilterValidator class file.
4 *
5 * @author Qiang Xue <qiang.xue@gmail.com>
6 * @link http://www.yiiframework.com/
4be0af6 changed copyright year.
qiang.xue authored
7 * @copyright Copyright &copy; 2008-2011 Yii Software LLC
55bdd95 removed carriage returns from files.
qiang.xue authored
8 * @license http://www.yiiframework.com/license/
9 */
10
11 /**
12 * CFilterValidator transforms the data being validated based on a filter.
13 *
14 * CFilterValidator is actually not a validator but a data processor.
15 * It invokes the specified filter method to process the attribute value
16 * and save the processed value back to the attribute. The filter method
17 * must follow the following signature:
18 * <pre>
19 * function foo($value) {...return $newValue; }
20 * </pre>
21 * Many PHP functions qualify this signature (e.g. trim).
22 *
23 * To specify the filter method, set {@link filter} property to be the function name.
24 *
25 * @author Qiang Xue <qiang.xue@gmail.com>
26 * @package system.validators
27 * @since 1.0
28 */
29 class CFilterValidator extends CValidator
30 {
31 /**
32 * @var callback the filter method
33 */
34 public $filter;
35
36 /**
662798d
qiang.xue authored
37 * Validates the attribute of the object.
38 * If there is any error, the error message is added to the object.
72b9745 Updated PHPDoc @param parameter names
mdomba authored
39 * @param CModel $object the object being validated
40 * @param string $attribute the attribute being validated
55bdd95 removed carriage returns from files.
qiang.xue authored
41 */
42 protected function validateAttribute($object,$attribute)
43 {
f6e3bad Fixed a bug in CFilterValidator about setting filter property.
qiang.xue authored
44 if($this->filter===null || !is_callable($this->filter))
cf9b8de Changed Yii::t() and added a category parameter as its first parameter
qiang.xue authored
45 throw new CException(Yii::t('yii','The "filter" property must be specified with a valid callback.'));
c168b8a merge from 1.0
qiang.xue authored
46 $object->$attribute=call_user_func_array($this->filter,array($object->$attribute));
55bdd95 removed carriage returns from files.
qiang.xue authored
47 }
48 }
Something went wrong with that request. Please try again.