1: <?php
2: /**
3: * Copyright 2013-2014 Horde LLC (http://www.horde.org/)
4: *
5: * See the enclosed file COPYING for license information (GPL). If you
6: * did not receive this file, see http://www.horde.org/licenses/gpl.
7: *
8: * @category Horde
9: * @copyright 2013-2014 Horde LLC
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @package IMP
12: */
13:
14: /**
15: * Extension of IMP_Compose_Exception that handles the situation of invalid
16: * address input. Allows details of individual e-mail address errors to be
17: * communicated to the user.
18: *
19: * @author Michael Slusarz <slusarz@horde.org>
20: * @category Horde
21: * @copyright 2013-2014 Horde LLC
22: * @license http://www.horde.org/licenses/gpl GPL
23: * @package IMP
24: */
25: class IMP_Compose_Exception_Address
26: extends IMP_Compose_Exception
27: implements Countable, IteratorAggregate
28: {
29: /* Severity level. */
30: const BAD = 1;
31: const WARN = 2;
32:
33: /**
34: * The list of error addresses.
35: *
36: * @var array
37: */
38: protected $_addresses = array();
39:
40: /**
41: * Add an address to the bad list.
42: *
43: * @param Horde_Mail_Rfc822_Object $address Bad address.
44: * @param Exception|string $msg Error message.
45: * @param integer $level Severity level.
46: */
47: public function addAddress(
48: Horde_Mail_Rfc822_Object $address, $msg, $level = self::BAD
49: )
50: {
51: $ob = new stdClass;
52: $ob->address = $address;
53: $ob->error = ($msg instanceof Exception)
54: ? $msg->getMessage()
55: : strval($msg);
56: $ob->level = $level;
57:
58: $this->_addresses[] = $ob;
59: }
60:
61: /* Countable method. */
62:
63: /**
64: * Returns the number of error addresses.
65: *
66: * @return integer The number of error addresses.
67: */
68: public function count()
69: {
70: return count($this->_addresses);
71: }
72:
73: /* IteratorAggregate method. */
74:
75: /**
76: */
77: public function getIterator()
78: {
79: return new ArrayIterator($this->_addresses);
80: }
81:
82: }
83: