Back to index

d-push  2.0
class.baseexception.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  * Copyright 2005 - 2012  Zarafa B.V.
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU Affero General Public License, version 3,
00007  * as published by the Free Software Foundation with the following additional
00008  * term according to sec. 7:
00009  *
00010  * According to sec. 7 of the GNU Affero General Public License, version
00011  * 3, the terms of the AGPL are supplemented with the following terms:
00012  *
00013  * "Zarafa" is a registered trademark of Zarafa B.V. The licensing of
00014  * the Program under the AGPL does not imply a trademark license.
00015  * Therefore any rights, title and interest in our trademarks remain
00016  * entirely with us.
00017  *
00018  * However, if you propagate an unmodified version of the Program you are
00019  * allowed to use the term "Zarafa" to indicate that you distribute the
00020  * Program. Furthermore you may use our trademarks where it is necessary
00021  * to indicate the intended purpose of a product or service provided you
00022  * use it in accordance with honest practices in industrial or commercial
00023  * matters.  If you want to propagate modified versions of the Program
00024  * under the name "Zarafa" or "Zarafa Server", you may only do so if you
00025  * have a written permission by Zarafa B.V. (to acquire a permission
00026  * please contact Zarafa at trademark@zarafa.com).
00027  *
00028  * The interactive user interface of the software displays an attribution
00029  * notice containing the term "Zarafa" and/or the logo of Zarafa.
00030  * Interactive user interfaces of unmodified and modified versions must
00031  * display Appropriate Legal Notices according to sec. 5 of the GNU
00032  * Affero General Public License, version 3, when you propagate
00033  * unmodified or modified versions of the Program. In accordance with
00034  * sec. 7 b) of the GNU Affero General Public License, version 3, these
00035  * Appropriate Legal Notices must retain the logo of Zarafa or display
00036  * the words "Initial Development by Zarafa" if the display of the logo
00037  * is not reasonably feasible for technical reasons. The use of the logo
00038  * of Zarafa in Legal Notices is allowed for unmodified and modified
00039  * versions of the software.
00040  *
00041  * This program is distributed in the hope that it will be useful,
00042  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00043  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00044  * GNU Affero General Public License for more details.
00045  *
00046  * You should have received a copy of the GNU Affero General Public License
00047  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00048  *
00049  */
00050 
00051 
00065 class BaseException extends Exception
00066 {
00071     private $_previous = null;
00072 
00076     private $baseFile = null;
00077 
00081     public $isHandled = false;
00082 
00086     public $displayMessage = null;
00087 
00097     public function __construct($errorMessage, $code = 0, Exception $previous = null, $displayMessage = null) {
00098         // assign display message
00099         $this->displayMessage = $displayMessage;
00100 
00101         if (version_compare(PHP_VERSION, '5.3.0', '<')) {
00102             parent::__construct($errorMessage, (int) $code);
00103 
00104             // set previous exception
00105             if(!is_null($previous)) {
00106                 $this->_previous = $previous;
00107             }
00108         } else {
00109             parent::__construct($errorMessage, (int) $code, $previous);
00110         }
00111     }
00112 
00120     public function __call($method, array $args)
00121     {
00122         if ('getprevious' == strtolower($method)) {
00123             return $this->_getPrevious();
00124         }
00125 
00126         return null;
00127     }
00128 
00132     public function getFileLine()
00133     {
00134         return $this->getBaseFile() . ':' . $this->getLine();
00135     }
00136 
00140     public function getDisplayMessage()
00141     {
00142         if(!is_null($this->displayMessage)) {
00143             return $this->displayMessage;
00144         }
00145 
00146         return $this->getMessage();
00147     }
00148 
00154     public function setDisplayMessage($message)
00155     {
00156         $this->displayMessage = $message;
00157     }
00158 
00164     public function setHandled()
00165     {
00166         $this->isHandled = true;
00167     }
00168 
00172     public function getBaseFile()
00173     {
00174         if(is_null($this->baseFile)) {
00175             $this->baseFile = basename(parent::getFile());
00176         }
00177 
00178         return $this->baseFile;
00179     }
00180 
00187     public function _getPrevious()
00188     {
00189         if (version_compare(PHP_VERSION, '5.3.0', '<')) {
00190             return $this->_previous;
00191         } else {
00192             return parent::getPrevious();
00193         }
00194     }
00195 
00201     public function __toString()
00202     {
00203         if (version_compare(PHP_VERSION, '5.3.0', '<')) {
00204             if (($e = $this->getPrevious()) !== null) {
00205                 return $e->__toString()
00206                         . "\n\nNext "
00207                         . parent::__toString();
00208             }
00209         }
00210 
00211         return parent::__toString();
00212     }
00213 
00219     public function getName()
00220     {
00221         return get_class($this);
00222     }
00223 
00224     // @TODO getTrace and getTraceAsString
00225 }
00226 ?>