Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'hotfix/3480'

Close #3480
Fixes #2538
  • Loading branch information...
commit 10611f7a8c4d38637a0b40cb2a4b1f9b7dcc4928 2 parents 9b7c06c + 7604499
Matthew Weier O'Phinney weierophinney authored
18 library/Zend/Validator/EmailAddress.php
View
@@ -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);
}
16 tests/ZendTest/Validator/EmailAddressTest.php
View
@@ -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);
+ }
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.