Orion PHP  0.11.12
The PHP5.3 framework
exception.php
Go to the documentation of this file.
00001 <?php
00002 
00003 namespace Orion\Core;
00004 
00005 
00006 /**
00007  * \Orion\Core\Exception
00008  * 
00009  * Orion exception class.
00010  *
00011  * Extends standard Exception but with caller class handler
00012  *
00013  * @author Thibaut Despoulain
00014  * @license BSD 4-clauses
00015  * @version 0.11.12
00016  */
00017 class Exception extends \Exception
00018 {
00019 
00020     protected $classname;
00021 
00022     /**
00023      * Generates Exception
00024      * @param string $message
00025      * @param int $code
00026      * @param string $caller Caller class' name
00027      */
00028     public function __construct( $message='An exception occured', $code=256, $caller=null )
00029     {
00030         parent::__construct( ( string ) $message, ( int ) $code );
00031         $this->classname = $caller;
00032     }
00033 
00034     /**
00035      * Logs error to root error.log file
00036      */
00037     public function log()
00038     {
00039         $text = "\n" . date( '[d/m/Y@H:i:s]' ) . ' ' . $this->getCode() . ' : ' . $this->getMessage() . ' (line ' . $this->getLine() . ' in ' . $this->getFile() . ')';
00040         file_put_contents( 'error.log', $text, FILE_APPEND );
00041     }
00042 
00043     public function traceback()
00044     {
00045         debug_print_backtrace();
00046     }
00047 
00048     public function __toString()
00049     {
00050         switch ( $this->code )
00051         {
00052             case E_USER_ERROR :
00053                 $type = 'Fatal error';
00054                 break;
00055 
00056             case E_WARNING :
00057             case E_USER_WARNING :
00058                 $type = 'Warning';
00059                 break;
00060 
00061             case E_NOTICE :
00062             case E_USER_NOTICE :
00063                 $type = 'Notice';
00064                 break;
00065 
00066             default :
00067                 $type = 'Unknown error';
00068                 break;
00069         }
00070 
00071         return '<p><strong>' . $type . '</strong> : [' . $this->code . '] ' . $this->classname . ' : ' . $this->message . '</p>';
00072     }
00073 
00074 }
00075 
00076 ?>