OXID eShop CE  4.10.2
 All Classes Namespaces Files Functions Variables Pages
oxexceptionhandler.php
Go to the documentation of this file.
1 <?php
2 
7 {
8 
16  protected $_sFileName = 'EXCEPTION_LOG.txt';
17 
23  protected $_iDebug = 0;
24 
30  public function __construct($iDebug = 0)
31  {
32  $this->_iDebug = (int) $iDebug;
33  }
34 
40  public function setIDebug($iDebug)
41  {
42  $this->_iDebug = $iDebug;
43  }
44 
52  public function setLogFileName($sFile)
53  {
54  $this->_sFileName = $sFile;
55  }
56 
64  public function getLogFileName()
65  {
66  return $this->_sFileName;
67  }
68 
76  public function handleUncaughtException(Exception $oEx)
77  {
78  // split between php or shop exception
79  if (!$oEx instanceof oxException) {
80  $this->_dealWithNoOxException($oEx);
81 
82  return; // Return straight away ! (in case of unit testing)
83  }
84 
85  $oEx->setLogFileName($this->_sFileName); // set common log file ...
86 
87  $this->_uncaughtException($oEx); // Return straight away ! (in case of unit testing)
88  }
89 
97  protected function _uncaughtException(oxException $oEx)
98  {
99  // exception occurred in function processing
100  $oEx->setNotCaught();
101  // general log entry for all exceptions here
102  $oEx->debugOut();
103 
104  if (defined('OXID_PHP_UNIT')) {
105  return $oEx->getString();
106  } elseif (0 != $this->_iDebug) {
107  oxRegistry::getUtils()->showMessageAndExit($oEx->getString());
108  }
109 
110  try {
111  oxRegistry::getUtils()->redirectOffline(500);
112  } catch (Exception $oException) {
113  }
114 
115  exit();
116  }
117 
125  protected function _dealWithNoOxException(Exception $oEx)
126  {
127  if (0 != $this->_iDebug) {
128  $sLogMsg = date('Y-m-d H:i:s') . $oEx . "\n---------------------------------------------\n";
129  //deprecated since v5.3 (2016-06-17); Logging mechanism will be changed in 6.0.
130  oxRegistry::getUtils()->writeToLog($sLogMsg, $this->getLogFileName());
131  //end deprecated
132  if (defined('OXID_PHP_UNIT')) {
133  return;
134  } elseif (0 != $this->_iDebug) {
135  oxRegistry::getUtils()->showMessageAndExit($sLogMsg);
136  }
137  }
138 
139  try {
140  oxRegistry::getUtils()->redirectOffline(500);
141  } catch (Exception $oException) {
142  }
143 
144  exit();
145  }
146 
158  public function __call($sMethod, $aArgs)
159  {
160  if (defined('OXID_PHP_UNIT')) {
161  if (substr($sMethod, 0, 4) == "UNIT") {
162  $sMethod = str_replace("UNIT", "_", $sMethod);
163  }
164  if (method_exists($this, $sMethod)) {
165  return call_user_func_array(array(& $this, $sMethod), $aArgs);
166  }
167  }
168 
169  throw new oxSystemComponentException("Function '$sMethod' does not exist or is not accessible! (" . __CLASS__ . ")" . PHP_EOL);
170  }
171 }