[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/validator/ -> sfUrlValidator.class.php (source)

   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: sfUrlValidator.class.php 3345 2007-01-29 10:25:09Z fabien $
  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  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7