Go to the documentation of this file.00001 <?php
00002
00006 class oxExceptionHandler
00007 {
00013 protected $_sFileName = 'EXCEPTION_LOG.txt';
00014
00020 protected $_iDebug = 0;
00021
00027 public function __construct( $iDebug = 0 )
00028 {
00029 $this->_iDebug = (int) $iDebug;
00030 }
00031
00039 public function setIDebug($iDebug)
00040 {
00041 $this->_iDebug = $iDebug;
00042 }
00043
00051 public function setLogFileName($sFile)
00052 {
00053 $this->_sFileName = $sFile;
00054 }
00055
00061 public function getLogFileName()
00062 {
00063 return $this->_sFileName;
00064 }
00065
00073 public function handleUncaughtException( Exception $oEx )
00074 {
00075
00076 if ( !$oEx instanceof oxException ) {
00077 $this->_dealWithNoOxException( $oEx );
00078 return;
00079 }
00080
00081 $oEx->setLogFileName( $this->_sFileName );
00082
00083 $this->_uncaughtException( $oEx );
00084 }
00085
00093 protected function _uncaughtException( oxException $oEx )
00094 {
00095
00096 $oEx->setNotCaught();
00097
00098 $oEx->debugOut();
00099
00100 if ( defined( 'OXID_PHP_UNIT' ) ) {
00101 return $oEx->getString();
00102 } elseif ( 0 != $this->_iDebug ) {
00103 oxRegistry::getUtils()->showMessageAndExit( $oEx->getString() );
00104 }
00105
00106 try {
00107 oxRegistry::getUtils()->redirectOffline(500);
00108 } catch (Exception $oException) {}
00109
00110 exit();
00111 }
00112
00120 protected function _dealWithNoOxException( Exception $oEx )
00121 {
00122 if ( 0 != $this->_iDebug ) {
00123 $sLogMsg = date( 'Y-m-d H:i:s' ) . $oEx . "\n---------------------------------------------\n";
00124 oxRegistry::getUtils()->writeToLog( $sLogMsg, $this->getLogFileName() );
00125 if ( defined( 'OXID_PHP_UNIT' ) ) {
00126 return;
00127 } elseif ( 0 != $this->_iDebug ) {
00128 oxRegistry::getUtils()->showMessageAndExit( $sLogMsg );
00129 }
00130 }
00131
00132 try {
00133 oxRegistry::getUtils()->redirectOffline(500);
00134 } catch (Exception $oException) {}
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 }