oxexceptionhandler.php

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

Generated on Wed May 13 13:25:51 2009 for OXID eShop CE by  doxygen 1.5.5