Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

[Validator][#2538] hostname validator overwrite #3480

Closed
wants to merge 2 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+17 −17
Split
@@ -104,10 +104,6 @@ public function __construct($options = array())
$options = $temp;
}
- if (!array_key_exists('hostnameValidator', $options)) {
- $options['hostnameValidator'] = null;
- }
-
parent::__construct($options);
}
@@ -139,14 +135,14 @@ public function setMessage($messageString, $messageKey = null)
/**
* Returns the set hostname validator
*
+ * If was not previously set then lazy load a new one
+ *
* @return Hostname
*/
public function getHostnameValidator()
{
- if (!isset($this->options['hostnameValidator'])
- || !$this->options['hostnameValidator'] instanceof Hostname
- ) {
- $this->setHostnameValidator();
+ if (!isset($this->options['hostnameValidator'])) {
+ $this->options['hostnameValidator'] = new Hostname($this->getAllow());
}
return $this->options['hostnameValidator'];
@@ -158,10 +154,6 @@ public function getHostnameValidator()
*/
public function setHostnameValidator(Hostname $hostnameValidator = null)
{
- if (!$hostnameValidator) {
- $hostnameValidator = new Hostname($this->getAllow());
- }
-
$this->options['hostnameValidator'] = $hostnameValidator;
return $this;
@@ -186,7 +178,7 @@ public function getAllow()
public function setAllow($allow)
{
$this->options['allow'] = $allow;
- if ($this->options['hostnameValidator'] !== null) {
+ if (isset($this->options['hostnameValidator'])) {
$this->options['hostnameValidator']->setAllow($allow);
}
@@ -522,8 +522,12 @@ public function testSetSingleMessage()
public function testSetSingleMessageViaOptions()
{
$validator = new EmailAddress(array('message' => 'TestMessage'));
- $messages = $validator->getMessageTemplates();
- $this->assertEquals('TestMessage', $messages[EmailAddress::INVALID]);
+ foreach ($validator->getMessageTemplates() as $message) {
+ $this->assertEquals('TestMessage', $message);
+ }
+ foreach ($validator->getHostnameValidator()->getMessageTemplates() as $message) {
+ $this->assertEquals('TestMessage', $message);
+ }
}
public function testSetMultipleMessageViaOptions()
@@ -559,8 +563,12 @@ public function testSetMultipleMessages()
$messages = $this->validator->getMessageTemplates();
$this->assertNotEquals('TestMessage', $messages[EmailAddress::INVALID]);
$this->validator->setMessage('TestMessage');
- $messages = $this->validator->getMessageTemplates();
- $this->assertEquals('TestMessage', $messages[EmailAddress::INVALID]);
+ foreach ($this->validator->getMessageTemplates() as $message) {
+ $this->assertEquals('TestMessage', $message);
+ }
+ foreach ($this->validator->getHostnameValidator()->getMessageTemplates() as $message) {
+ $this->assertEquals('TestMessage', $message);
+ }
}
/**