1: <?php
2: /**
3: * The IMP_Compose_Exception:: class handles exceptions thrown from the
4: * IMP_Compose class.
5: *
6: * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
7: *
8: * See the enclosed file COPYING for license information (GPL). If you
9: * did not receive this file, see http://www.horde.org/licenses/gpl.
10: *
11: * @author Michael Slusarz <slusarz@horde.org>
12: * @category Horde
13: * @license http://www.horde.org/licenses/gpl GPL
14: * @package IMP
15: */
16: class IMP_Compose_Exception extends IMP_Exception
17: {
18: /**
19: * Stores information on whether an encryption dialog window needs
20: * to be opened.
21: *
22: * @var string
23: */
24: public $encrypt = null;
25:
26: /**
27: * If set, indicates that this identity matches the given to address.
28: *
29: * @var integer
30: */
31: public $tied_identity = null;
32:
33: /**
34: * If true, exception was already logged.
35: *
36: * @var boolean
37: */
38: protected $_logged = false;
39:
40: /**
41: * Creates a new Exception object and immediately logs the message.
42: *
43: * @param string $log The log level to immediately log the message to.
44: * If empty, will only log message if log() is
45: * explicitly called.
46: * @param mixed $message The exception message, PEAR_Error object, or
47: * Exception object.
48: * @param integer $code A numeric error code.
49: *
50: * @return IMP_Compose_Exception Exception argument.
51: */
52: static public function createAndLog()
53: {
54: $e = new self(func_get_arg(1), func_num_args() == 3 ? func_get_arg(2) : null);
55: $e->log(func_get_arg(0));
56: return $e;
57: }
58:
59: /**
60: * Log error message.
61: *
62: * @param string $level Level to log at.
63: *
64: * @return boolean True if message was logged.
65: */
66: public function log($level = 'ERR')
67: {
68: if ($this->_logged) {
69: return false;
70: }
71:
72: Horde::logMessage($this, $level);
73: $this->_logged = true;
74:
75: return true;
76: }
77:
78: }
79: