|
Revision 7902, 1.6 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 |
class sfUrlValidator extends sfValidator |
|---|
| 20 |
{ |
|---|
| 21 |
|
|---|
| 22 |
* Executes this validator. |
|---|
| 23 |
* |
|---|
| 24 |
* @param mixed A file or parameter value/array |
|---|
| 25 |
* @param error An error message reference |
|---|
| 26 |
* |
|---|
| 27 |
* @return bool true, if this validator executes successfully, otherwise false |
|---|
| 28 |
*/ |
|---|
| 29 |
public function execute(&$value, &$error) |
|---|
| 30 |
{ |
|---|
| 31 |
$re = '/^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)/i'; |
|---|
| 32 |
|
|---|
| 33 |
if (!preg_match($re, $value)) |
|---|
| 34 |
{ |
|---|
| 35 |
$error = $this->getParameterHolder()->get('url_error'); |
|---|
| 36 |
return false; |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
return true; |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
* Initializes this validator. |
|---|
| 44 |
* |
|---|
| 45 |
* @param sfContext The current application context |
|---|
| 46 |
* @param array An associative array of initialization parameters |
|---|
| 47 |
* |
|---|
| 48 |
* @return bool true, if initialization completes successfully, otherwise false |
|---|
| 49 |
*/ |
|---|
| 50 |
public function initialize($context, $parameters = null) |
|---|
| 51 |
{ |
|---|
| 52 |
|
|---|
| 53 |
parent::initialize($context); |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
$this->getParameterHolder()->set('url_error', 'Invalid input'); |
|---|
| 57 |
|
|---|
| 58 |
$this->getParameterHolder()->add($parameters); |
|---|
| 59 |
|
|---|
| 60 |
return true; |
|---|
| 61 |
} |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|