*/ class tao_helpers_form_validators_Url extends tao_helpers_form_Validator { private const OPTION_ALLOW_EMPTY = 'allow_empty'; /** * @author Bertrand Chevrier, */ public function __construct(array $options = []) { parent::__construct($options); } /** * @param string $value * @return bool */ public function evaluate($value) { if ('' === $value && $this->hasOption(self::OPTION_ALLOW_EMPTY) && $this->getOption(self::OPTION_ALLOW_EMPTY) == true) { return true; } //backward compatible behavior: //scheme should be prepended if not found (pattern includes spelling errors) if (preg_match('/^[a-zA-Z]{1,10}[:\/]{1,3}/', $value) === false) { $value = 'http://' . $value; } $returnValue = !(filter_var($value, FILTER_VALIDATE_URL) === false); //'isset' is backward compatible behavior if (!$this->hasOption('allow_parameters')) { $returnValue = $returnValue && (strpos($value, '?') === false); } return $returnValue; } /** * Default error message * * @return string */ protected function getDefaultMessage() { return __('Provided URL is not valid'); } }