/** * Validate a domain name value * * @return void * @throws \Magento\Framework\Model\Exception */ protected function _beforeSave() { $value = $this->getValue(); $validator = new \Zend\Validator\Hostname(\Zend\Validator\Hostname::ALLOW_ALL); // Empty value is treated valid and will be handled when read the value out if (!empty($value) && !$validator->isValid($value)) { throw new \Magento\Framework\Model\Exception('Invalid domain name: ' . join('; ', $validator->getMessages())); } }
/** * {@inheritdoc} */ public function isValid($value) { $this->_clearMessages(); if (!is_string($value)) { $this->_addMessages(['must be a string']); return false; } $validator = new \Zend\Validator\Hostname(\Zend\Validator\Hostname::ALLOW_ALL); if (!empty($value) && !$validator->isValid($value)) { $this->_addMessages($validator->getMessages()); return false; } return true; }
/** * Set session.cookie_domain * * @param string $cookieDomain * @return $this * @throws \InvalidArgumentException */ public function setCookieDomain($cookieDomain) { if (!is_string($cookieDomain)) { throw new \InvalidArgumentException('Invalid cookie domain: must be a string'); } $validator = new \Zend\Validator\Hostname(\Zend\Validator\Hostname::ALLOW_ALL); if (!empty($cookieDomain) && !$validator->isValid($cookieDomain)) { throw new \InvalidArgumentException('Invalid cookie domain: ' . join('; ', $validator->getMessages())); } $this->setOption('session.cookie_domain', $cookieDomain); return $this; }