Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
KeyLength.php
Go to the documentation of this file.
1 <?php
7 
12 {
18  protected $_name = 'Key';
19 
23  protected $_messageTemplates = [
24  self::INVALID => "Invalid type given for %name%. String expected",
25  self::TOO_SHORT => "%name% '%value%' is less than %min% characters long",
26  self::TOO_LONG => "%name% '%value%' is more than %max% characters long",
27  ];
28 
34  protected $_messageVariables = ['min' => '_min', 'max' => '_max', 'name' => '_name'];
35 
44  public function __construct($options = [])
45  {
46  if (!is_array($options)) {
47  $options = func_get_args();
48  if (!isset($options[1])) {
49  $options[1] = 'utf-8';
50  }
51  parent::__construct($options[0], $options[0], $options[1]);
52  return;
53  } else {
54  if (isset($options['length'])) {
55  $options['max'] = $options['min'] = $options['length'];
56  }
57  if (isset($options['name'])) {
58  $this->_name = $options['name'];
59  }
60  }
61  parent::__construct($options);
62  }
63 
70  public function setLength($length)
71  {
72  parent::setMax($length);
73  parent::setMin($length);
74  return $this;
75  }
76 
82  public function getLength()
83  {
84  return parent::getMin();
85  }
86 
97  public function isValid($value)
98  {
99  $result = parent::isValid($value);
100  if (!$result && isset($this->_messages[self::INVALID])) {
101  throw new \Exception($this->_messages[self::INVALID]);
102  }
103  return $result;
104  }
105 
112  public function setName($name)
113  {
114  $this->_name = $name;
115  return $this;
116  }
117 
123  public function getName()
124  {
125  return $this->_name;
126  }
127 }
$value
Definition: gender.phtml:16
if(!isset($_GET['name'])) $name
Definition: log.php:14