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