|
Revision 7902, 2.4 kB
(checked in by fabien, 5 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 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
class sfCallbackValidator extends sfValidator |
|---|
| 32 |
{ |
|---|
| 33 |
|
|---|
| 34 |
* Executes this validator. |
|---|
| 35 |
* |
|---|
| 36 |
* @param string A parameter value |
|---|
| 37 |
* @param string An error message reference |
|---|
| 38 |
* |
|---|
| 39 |
* @return boolean true, if this validator executes successfully, otherwise false |
|---|
| 40 |
*/ |
|---|
| 41 |
public function execute(&$value, &$error) |
|---|
| 42 |
{ |
|---|
| 43 |
$callback = $this->getParameterHolder()->get('callback'); |
|---|
| 44 |
|
|---|
| 45 |
if (!call_user_func($callback, $value)) |
|---|
| 46 |
{ |
|---|
| 47 |
$error = $this->getParameterHolder()->get('invalid_error'); |
|---|
| 48 |
|
|---|
| 49 |
return false; |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
return true; |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
* Initializes this validator. |
|---|
| 57 |
* |
|---|
| 58 |
* @param sfContext The current application context |
|---|
| 59 |
* @param array An associative array of initialization parameters |
|---|
| 60 |
* |
|---|
| 61 |
* @return boolean true, if initialization completes successfully, otherwise false |
|---|
| 62 |
*/ |
|---|
| 63 |
public function initialize($context, $parameters = null) |
|---|
| 64 |
{ |
|---|
| 65 |
|
|---|
| 66 |
parent::initialize($context); |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
$this->getParameterHolder()->set('callback', null); |
|---|
| 70 |
$this->getParameterHolder()->set('invalid_error', 'Invalid input'); |
|---|
| 71 |
|
|---|
| 72 |
$this->getParameterHolder()->add($parameters); |
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
if (!is_callable($this->getParameterHolder()->get('callback'))) |
|---|
| 76 |
{ |
|---|
| 77 |
|
|---|
| 78 |
throw new sfValidatorException('Callback function must be a valid callback using is_callable().'); |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
return true; |
|---|
| 82 |
} |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|