Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Validator.php
Go to the documentation of this file.
1 <?php
12 namespace Magento\Framework\Url;
13 
15 {
19  const INVALID_URL = 'invalidUrl';
25  private $validator;
26 
30  public function __construct(\Zend\Validator\Uri $validator)
31  {
32  // set translated message template
33  $this->setMessage((string)new \Magento\Framework\Phrase("Invalid URL '%value%'."), self::INVALID_URL);
34  $this->validator = $validator;
35  $this->validator->setAllowRelative(false);
36  }
37 
43  protected $_messageTemplates = [self::INVALID_URL => "Invalid URL '%value%'."];
44 
51  public function isValid($value)
52  {
53  $this->_setValue($value);
54 
55  $valid = $this->validator->isValid($value);
56 
57  if (!$valid) {
58  $this->_error(self::INVALID_URL);
59  }
60 
61  return $valid;
62  }
63 }
__construct(\Zend\Validator\Uri $validator)
Definition: Validator.php:30
_error($messageKey, $value=null)
Definition: Abstract.php:284
$value
Definition: gender.phtml:16
setMessage($messageString, $messageKey=null)
Definition: Abstract.php:141