Development

/branches/1.3/lib/plugins/sfCompat10Plugin/lib/validator/sfUrlValidator.class.php

You must first sign up to be able to contribute.

root/branches/1.3/lib/plugins/sfCompat10Plugin/lib/validator/sfUrlValidator.class.php

Revision 7902, 1.6 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) 2004-2006 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  * sfUrlValidator verifies a parameter contains a value that qualifies as a valid URL.
13  *
14  * @package    symfony
15  * @subpackage validator
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
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     // initialize parent
53     parent::initialize($context);
54
55     // set defaults
56     $this->getParameterHolder()->set('url_error', 'Invalid input');
57
58     $this->getParameterHolder()->add($parameters);
59
60     return true;
61   }
62 }
63
Note: See TracBrowser for help on using the browser.