oxexceptionhandler.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class oxExceptionHandler
00007 {
00008 
00014     protected $_sFileName = 'EXCEPTION_LOG.txt';
00015 
00021     protected $_iDebug = 0;
00022 
00028     public function __construct($iDebug = 0)
00029     {
00030         $this->_iDebug = (int) $iDebug;
00031     }
00032 
00038     public function setIDebug($iDebug)
00039     {
00040         $this->_iDebug = $iDebug;
00041     }
00042 
00048     public function setLogFileName($sFile)
00049     {
00050         $this->_sFileName = $sFile;
00051     }
00052 
00058     public function getLogFileName()
00059     {
00060         return $this->_sFileName;
00061     }
00062 
00070     public function handleUncaughtException(Exception $oEx)
00071     {
00072         // split between php or shop exception
00073         if (!$oEx instanceof oxException) {
00074             $this->_dealWithNoOxException($oEx);
00075 
00076             return; // Return straight away ! (in case of unit testing)
00077         }
00078 
00079         $oEx->setLogFileName($this->_sFileName); // set common log file ...
00080 
00081         $this->_uncaughtException($oEx); // Return straight away ! (in case of unit testing)
00082     }
00083 
00091     protected function _uncaughtException(oxException $oEx)
00092     {
00093         // exception occurred in function processing
00094         $oEx->setNotCaught();
00095         // general log entry for all exceptions here
00096         $oEx->debugOut();
00097 
00098         if (defined('OXID_PHP_UNIT')) {
00099             return $oEx->getString();
00100         } elseif (0 != $this->_iDebug) {
00101             oxRegistry::getUtils()->showMessageAndExit($oEx->getString());
00102         }
00103 
00104         try {
00105             oxRegistry::getUtils()->redirectOffline(500);
00106         } catch (Exception $oException) {
00107         }
00108 
00109         exit();
00110     }
00111 
00119     protected function _dealWithNoOxException(Exception $oEx)
00120     {
00121         if (0 != $this->_iDebug) {
00122             $sLogMsg = date('Y-m-d H:i:s') . $oEx . "\n---------------------------------------------\n";
00123             oxRegistry::getUtils()->writeToLog($sLogMsg, $this->getLogFileName());
00124             if (defined('OXID_PHP_UNIT')) {
00125                 return;
00126             } elseif (0 != $this->_iDebug) {
00127                 oxRegistry::getUtils()->showMessageAndExit($sLogMsg);
00128             }
00129         }
00130 
00131         try {
00132             oxRegistry::getUtils()->redirectOffline(500);
00133         } catch (Exception $oException) {
00134         }
00135 
00136         exit();
00137     }
00138 
00150     public function __call($sMethod, $aArgs)
00151     {
00152         if (defined('OXID_PHP_UNIT')) {
00153             if (substr($sMethod, 0, 4) == "UNIT") {
00154                 $sMethod = str_replace("UNIT", "_", $sMethod);
00155             }
00156             if (method_exists($this, $sMethod)) {
00157                 return call_user_func_array(array(& $this, $sMethod), $aArgs);
00158             }
00159         }
00160 
00161         throw new oxSystemComponentException("Function '$sMethod' does not exist or is not accessible! (" . __CLASS__ . ")" . PHP_EOL);
00162     }
00163 }