]> dev.renevier.net Git - syj.git/blob - application/validate/EmailAddress.php
fixes logic error in div.addMessage method
[syj.git] / application / validate / EmailAddress.php
1 <?php
2 /*  This file is part of Syj, Copyright (c) 2010-2011 Arnaud Renevier,
3     and is published under the AGPL license. */
4
5 class Syj_Validate_EmailAddress extends Zend_Validate_EmailAddress {
6     public function __construct($options = array()) {
7         parent::__construct($options);
8         $this->setMailValidatorMessage();
9     }
10
11     protected function setMailValidatorMessage($message = null) {
12         if (!$message) {
13             $message = __("Invalid email");
14         }
15
16         foreach (array(Zend_Validate_EmailAddress::INVALID,
17                     Zend_Validate_EmailAddress::INVALID_FORMAT,
18                     Zend_Validate_EmailAddress::INVALID_HOSTNAME,
19                     Zend_Validate_EmailAddress::INVALID_MX_RECORD,
20                     Zend_Validate_EmailAddress::INVALID_SEGMENT,
21                     Zend_Validate_EmailAddress::DOT_ATOM,
22                     Zend_Validate_EmailAddress::QUOTED_STRING,
23                     Zend_Validate_EmailAddress::INVALID_LOCAL_PART,
24                     Zend_Validate_EmailAddress::LENGTH_EXCEEDED,
25
26                     Zend_Validate_Hostname::INVALID,
27                     Zend_Validate_Hostname::IP_ADDRESS_NOT_ALLOWED,
28                     Zend_Validate_Hostname::UNKNOWN_TLD,
29                     Zend_Validate_Hostname::INVALID_DASH,
30                     Zend_Validate_Hostname::INVALID_HOSTNAME_SCHEMA,
31                     Zend_Validate_Hostname::UNDECIPHERABLE_TLD,
32                     Zend_Validate_Hostname::INVALID_HOSTNAME,
33                     Zend_Validate_Hostname::INVALID_LOCAL_NAME,
34                     Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED,
35                     Zend_Validate_Hostname::CANNOT_DECODE_PUNYCODE) as $key) {
36             $this->setMessage($message, $key);
37         }
38     }
39
40     public function isValid($value) {
41         $valid = parent::isValid($value);
42         // only one error message
43         if (!$valid) {
44             $this->_messages = array(current($this->_messages));
45             $this->_errors = array(current($this->_errors));
46         }
47         return $valid;
48     }
49 }
50
51 ?>