| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
abstract class sfValidator |
|---|
| 25 |
{ |
|---|
| 26 |
protected |
|---|
| 27 |
$parameterHolder = null, |
|---|
| 28 |
$context = null; |
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
* Class constructor. |
|---|
| 32 |
* |
|---|
| 33 |
* @see initialize() |
|---|
| 34 |
*/ |
|---|
| 35 |
public function __construct($context, $parameters = array()) |
|---|
| 36 |
{ |
|---|
| 37 |
$this->initialize($context, $parameters); |
|---|
| 38 |
} |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
* Initializes this validator. |
|---|
| 42 |
* |
|---|
| 43 |
* @param sfContext The current application context |
|---|
| 44 |
* @param array An associative array of initialization parameters |
|---|
| 45 |
* |
|---|
| 46 |
* @return bool true, if initialization completes successfully, otherwise false |
|---|
| 47 |
*/ |
|---|
| 48 |
public function initialize($context, $parameters = array()) |
|---|
| 49 |
{ |
|---|
| 50 |
$this->context = $context; |
|---|
| 51 |
|
|---|
| 52 |
$this->parameterHolder = new sfParameterHolder(); |
|---|
| 53 |
$this->parameterHolder->add($parameters); |
|---|
| 54 |
|
|---|
| 55 |
return true; |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
* Executes this validator. |
|---|
| 60 |
* |
|---|
| 61 |
* @param mixed A file or parameter value/array |
|---|
| 62 |
* @param string An error message reference |
|---|
| 63 |
* |
|---|
| 64 |
* @return bool true, if this validator executes successfully, otherwise false |
|---|
| 65 |
*/ |
|---|
| 66 |
abstract function execute(&$value, &$error); |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
* Retrieves the current application context. |
|---|
| 70 |
* |
|---|
| 71 |
* @return sfContext The current sfContext instance |
|---|
| 72 |
*/ |
|---|
| 73 |
public final function getContext() |
|---|
| 74 |
{ |
|---|
| 75 |
return $this->context; |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
* Retrieves the parameters from the validator. |
|---|
| 80 |
* |
|---|
| 81 |
* @return sfParameterHolder List of parameters |
|---|
| 82 |
*/ |
|---|
| 83 |
public function getParameterHolder() |
|---|
| 84 |
{ |
|---|
| 85 |
return $this->parameterHolder; |
|---|
| 86 |
} |
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
* Retrieves a parameter from the validator. |
|---|
| 90 |
* |
|---|
| 91 |
* @param string Parameter name |
|---|
| 92 |
* @param mixed A default parameter value |
|---|
| 93 |
* |
|---|
| 94 |
* @return mixed A parameter value |
|---|
| 95 |
*/ |
|---|
| 96 |
public function getParameter($name, $default = null) |
|---|
| 97 |
{ |
|---|
| 98 |
return $this->parameterHolder->get($name, $default); |
|---|
| 99 |
} |
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
* Indicates whether or not a parameter exist for the validator. |
|---|
| 103 |
* |
|---|
| 104 |
* @param string A parameter name |
|---|
| 105 |
* |
|---|
| 106 |
* @return boolean true, if parameter exists, otherwise false |
|---|
| 107 |
*/ |
|---|
| 108 |
public function hasParameter($name) |
|---|
| 109 |
{ |
|---|
| 110 |
return $this->parameterHolder->has($name); |
|---|
| 111 |
} |
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
* Sets a parameter for the validator. |
|---|
| 115 |
* |
|---|
| 116 |
* @param string A parameter name |
|---|
| 117 |
* @param mixed A parameter value |
|---|
| 118 |
*/ |
|---|
| 119 |
public function setParameter($name, $value) |
|---|
| 120 |
{ |
|---|
| 121 |
$this->parameterHolder->set($name, $value); |
|---|
| 122 |
} |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|