Development

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

You must first sign up to be able to contribute.

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

Revision 10270, 1.7 kB (checked in by Carl.Vondrick, 6 years ago)

1.1: added deprecated warnings to all sfCompatPlugin classes (closes #3882)

  • 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  * WARNING: This class is deprecated and will be removed in symfony 1.2.
15  *
16  * @package    symfony
17  * @subpackage validator
18  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
19  * @version    SVN: $Id$
20  * @deprecated Deprecated since symfony 1.1
21  */
22 class sfUrlValidator extends sfValidator
23 {
24   /**
25    * Executes this validator.
26    *
27    * @param mixed A file or parameter value/array
28    * @param error An error message reference
29    *
30    * @return bool true, if this validator executes successfully, otherwise false
31    */
32   public function execute(&$value, &$error)
33   {
34     $re = '/^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)/i';
35
36     if (!preg_match($re, $value))
37     {
38       $error = $this->getParameterHolder()->get('url_error');
39       return false;
40     }
41
42     return true;
43   }
44
45   /**
46    * Initializes this validator.
47    *
48    * @param sfContext The current application context
49    * @param array   An associative array of initialization parameters
50    *
51    * @return bool true, if initialization completes successfully, otherwise false
52    */
53   public function initialize($context, $parameters = null)
54   {
55     // initialize parent
56     parent::initialize($context);
57
58     // set defaults
59     $this->getParameterHolder()->set('url_error', 'Invalid input');
60
61     $this->getParameterHolder()->add($parameters);
62
63     return true;
64   }
65 }
66
Note: See TracBrowser for help on using the browser.