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
00094 protected function _uncaughtException( oxException $oEx )
00095 {
00096
00097 $oEx->setNotCaught();
00098
00099 $oEx->debugOut();
00100
00101 if ( defined( 'OXID_PHP_UNIT' ) ) {
00102 return $oEx->getString();
00103 } elseif ( 0 != $this->_iDebug ) {
00104 oxRegistry::getUtils()->showMessageAndExit( $oEx->getString() );
00105 }
00106
00107
00108 $sShopUrl = oxRegistry::getConfig()->getSslShopUrl();
00109 $this->_safeShopRedirectAndExit( $sShopUrl . "offline.html" );
00110
00111
00112 return;
00113 }
00114
00123 protected function _dealWithNoOxException( Exception $oEx )
00124 {
00125 if ( 0 != $this->_iDebug ) {
00126 $sLogMsg = date( 'Y-m-d H:i:s' ) . $oEx . "\n---------------------------------------------\n";
00127 oxRegistry::getUtils()->writeToLog( $sLogMsg, $this->getLogFileName() );
00128 if ( defined( 'OXID_PHP_UNIT' ) ) {
00129 return;
00130 } elseif ( 0 != $this->_iDebug ) {
00131 oxRegistry::getUtils()->showMessageAndExit( $sLogMsg );
00132 }
00133 }
00134
00135 $sShopUrl = oxRegistry::getConfig()->getSslShopUrl();
00136 $this->_safeShopRedirectAndExit( $sShopUrl . "offline.html" );
00137 }
00138
00148 protected function _safeShopRedirectAndExit($sUrl)
00149 {
00150
00151 if ( defined('OXID_PHP_UNIT')) {
00152 return ;
00153 }
00154
00155
00156 header("HTTP/1.1 500 Internal Server Error");
00157 header("Location: ".$sUrl);
00158 header("Connection: close");
00159 exit();
00160 }
00161
00173 public function __call( $sMethod, $aArgs )
00174 {
00175 if ( defined( 'OXID_PHP_UNIT' ) ) {
00176 if ( substr( $sMethod, 0, 4) == "UNIT") {
00177 $sMethod = str_replace( "UNIT", "_", $sMethod);
00178 }
00179 if ( method_exists( $this, $sMethod)) {
00180 return call_user_func_array( array( & $this, $sMethod), $aArgs );
00181 }
00182 }
00183
00184 throw new oxSystemComponentException( "Function '$sMethod' does not exist or is not accessible! (".__CLASS__.")".PHP_EOL);
00185 }
00186 }