OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
oxexceptionhandler.php
Go to the documentation of this file.
1 <?php
2 
7 {
13  protected $_sFileName = 'EXCEPTION_LOG.txt';
14 
20  protected $_iDebug = 0;
21 
27  public function __construct( $iDebug = 0 )
28  {
29  $this->_iDebug = (int) $iDebug;
30  }
31 
39  public function setIDebug($iDebug)
40  {
41  $this->_iDebug = $iDebug;
42  }
43 
51  public function setLogFileName($sFile)
52  {
53  $this->_sFileName = $sFile;
54  }
55 
61  public function getLogFileName()
62  {
63  return $this->_sFileName;
64  }
65 
73  public function handleUncaughtException( Exception $oEx )
74  {
75  // split between php or shop exception
76  if ( !$oEx instanceof oxException ) {
77  $this->_dealWithNoOxException( $oEx );
78  return; // Return straight away ! (in case of unit testing)
79  }
80 
81  $oEx->setLogFileName( $this->_sFileName ); // set common log file ...
82 
83  $this->_uncaughtException( $oEx ); // Return straight away ! (in case of unit testing)
84  }
85 
93  protected function _uncaughtException( oxException $oEx )
94  {
95  // exception occurred in function processing
96  $oEx->setNotCaught();
97  // general log entry for all exceptions here
98  $oEx->debugOut();
99 
100  if ( defined( 'OXID_PHP_UNIT' ) ) {
101  return $oEx->getString();
102  } elseif ( 0 != $this->_iDebug ) {
103  oxRegistry::getUtils()->showMessageAndExit( $oEx->getString() );
104  }
105 
106  try {
107  oxRegistry::getUtils()->redirectOffline(500);
108  } catch (Exception $oException) {}
109 
110  exit();
111  }
112 
120  protected function _dealWithNoOxException( Exception $oEx )
121  {
122  if ( 0 != $this->_iDebug ) {
123  $sLogMsg = date( 'Y-m-d H:i:s' ) . $oEx . "\n---------------------------------------------\n";
124  oxRegistry::getUtils()->writeToLog( $sLogMsg, $this->getLogFileName() );
125  if ( defined( 'OXID_PHP_UNIT' ) ) {
126  return;
127  } elseif ( 0 != $this->_iDebug ) {
128  oxRegistry::getUtils()->showMessageAndExit( $sLogMsg );
129  }
130  }
131 
132  try {
133  oxRegistry::getUtils()->redirectOffline(500);
134  } catch (Exception $oException) {}
135 
136  exit();
137  }
138 
150  public function __call( $sMethod, $aArgs )
151  {
152  if ( defined( 'OXID_PHP_UNIT' ) ) {
153  if ( substr( $sMethod, 0, 4) == "UNIT") {
154  $sMethod = str_replace( "UNIT", "_", $sMethod);
155  }
156  if ( method_exists( $this, $sMethod)) {
157  return call_user_func_array( array( & $this, $sMethod), $aArgs );
158  }
159  }
160 
161  throw new oxSystemComponentException( "Function '$sMethod' does not exist or is not accessible! (".__CLASS__.")".PHP_EOL);
162  }
163 }