oxexceptionhandler.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxExceptionHandler
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 
00040     public function setIDebug($iDebug)
00041     {
00042         $this->_iDebug = $iDebug;
00043     }
00044 
00052     public function setLogFileName($sFile)
00053     {
00054         $this->_sFileName = $sFile;
00055     }
00056 
00062     public function getLogFileName()
00063     {
00064         return $this->_sFileName;
00065     }
00066 
00074     public function handleUncaughtException( Exception $oEx )
00075     {
00076         // split between php or shop exception
00077         if ( !$oEx instanceof oxException ) {
00078             $this->_dealWithNoOxException( $oEx );
00079             return;    // Return straight away ! (in case of unit testing)
00080         }
00081 
00082         $oEx->setLogFileName( $this->_sFileName );  // set common log file ...
00083 
00084         $this->_uncaughtException( $oEx );    // Return straight away ! (in case of unit testing)
00085     }
00086 
00095     protected function _uncaughtException( oxException $oEx )
00096     {
00097         // exception occured in function processing
00098         $oEx->setNotCaught();
00099         // general log entry for all exceptions here
00100         $oEx->debugOut($this->_iDebug);
00101 
00102         if ( defined( 'OXID_PHP_UNIT' ) ) {
00103             return $oEx->getString();
00104         } elseif ( 0 != $this->_iDebug ) {
00105             exit( $oEx->getString() );
00106         }
00107 
00108         //simple safe redirect in productive mode
00109         $this->_safeShopRedirectAndExit( "offline.html" );
00110 
00111         //should not be reached
00112         return ;
00113     }
00114 
00123     protected function _dealWithNoOxException( Exception $oEx )
00124     {
00125         if ( 0 != $this->_iDebug ) {
00126             $f = fopen( $this->_sFileName, 'a' );
00127             $sOut = date( 'Y-m-d H:i:s' ) . $oEx . "\n---------------------------------------------\n";
00128             fputs( $f, $sOut );
00129             fclose( $f );
00130 
00131             if ( defined( 'OXID_PHP_UNIT' ) ) {
00132                 return;
00133             } elseif ( 0 != $this->_iDebug ) {
00134                 exit( $sOut );
00135             }
00136         }
00137 
00138         $this->_safeShopRedirectAndExit( 'offline.html' );
00139 
00140     }
00141 
00151     protected function _safeShopRedirectAndExit($sUrl)
00152     {
00153         // No redirects in unit testing .. as redirection ends also unit testing script..
00154         if ( defined('OXID_PHP_UNIT')) {
00155             return ;
00156         }
00157 
00158         //make the redirect directly to be independetn from other objects
00159         header("HTTP/1.1 500 Internal Server Error");
00160         header("Location: ".$sUrl);
00161         header("Connection: close");
00162 
00163     }
00164 
00176     public function __call( $sMethod, $aArgs)
00177     {
00178         if ( defined( 'OXID_PHP_UNIT' ) ) {
00179             if ( substr( $sMethod, 0, 4) == "UNIT") {
00180                 $sMethod = str_replace( "UNIT", "_", $sMethod);
00181             }
00182             if ( method_exists( $this, $sMethod)) {
00183                 return call_user_func_array( array( & $this, $sMethod), $aArgs );
00184             }
00185         }
00186 
00187         throw new oxSystemComponentException( "Function '$sMethod' does not exist or is not accessable! (".__CLASS__.")".PHP_EOL);
00188     }
00189 }

Generated on Thu Dec 4 12:04:56 2008 for OXID eShop CE by  doxygen 1.5.5