OXID eShop CE  4.9.11
 All Classes Files Functions Variables Pages
oxexceptionhandler.php
Go to the documentation of this file.
1 <?php
2 
7 {
8 
14  protected $_sFileName = 'EXCEPTION_LOG.txt';
15 
21  protected $_iDebug = 0;
22 
28  public function __construct($iDebug = 0)
29  {
30  $this->_iDebug = (int) $iDebug;
31  }
32 
38  public function setIDebug($iDebug)
39  {
40  $this->_iDebug = $iDebug;
41  }
42 
48  public function setLogFileName($sFile)
49  {
50  $this->_sFileName = $sFile;
51  }
52 
58  public function getLogFileName()
59  {
60  return $this->_sFileName;
61  }
62 
70  public function handleUncaughtException(Exception $oEx)
71  {
72  // split between php or shop exception
73  if (!$oEx instanceof oxException) {
74  $this->_dealWithNoOxException($oEx);
75 
76  return; // Return straight away ! (in case of unit testing)
77  }
78 
79  $oEx->setLogFileName($this->_sFileName); // set common log file ...
80 
81  $this->_uncaughtException($oEx); // Return straight away ! (in case of unit testing)
82  }
83 
91  protected function _uncaughtException(oxException $oEx)
92  {
93  // exception occurred in function processing
94  $oEx->setNotCaught();
95  // general log entry for all exceptions here
96  $oEx->debugOut();
97 
98  if (defined('OXID_PHP_UNIT')) {
99  return $oEx->getString();
100  } elseif (0 != $this->_iDebug) {
101  oxRegistry::getUtils()->showMessageAndExit($oEx->getString());
102  }
103 
104  try {
105  oxRegistry::getUtils()->redirectOffline(500);
106  } catch (Exception $oException) {
107  }
108 
109  exit();
110  }
111 
119  protected function _dealWithNoOxException(Exception $oEx)
120  {
121  if (0 != $this->_iDebug) {
122  $sLogMsg = date('Y-m-d H:i:s') . $oEx . "\n---------------------------------------------\n";
123  oxRegistry::getUtils()->writeToLog($sLogMsg, $this->getLogFileName());
124  if (defined('OXID_PHP_UNIT')) {
125  return;
126  } elseif (0 != $this->_iDebug) {
127  oxRegistry::getUtils()->showMessageAndExit($sLogMsg);
128  }
129  }
130 
131  try {
132  oxRegistry::getUtils()->redirectOffline(500);
133  } catch (Exception $oException) {
134  }
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 }