OXID eShop CE  4.10.7
 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 
99  protected function _uncaughtException(oxException $oEx)
100  {
101  // exception occurred in function processing
102  $oEx->setNotCaught();
103  // general log entry for all exceptions here
104  $oEx->debugOut();
105 
106  if (defined('OXID_PHP_UNIT')) {
107  return $oEx->getString();
108  } elseif (0 != $this->_iDebug) {
109  oxRegistry::getUtils()->showMessageAndExit($oEx->getString());
110  }
111 
112  try {
113  oxRegistry::getUtils()->redirectOffline(500);
114  } catch (Exception $oException) {
115  }
116 
117  exit();
118  }
119 
129  protected function _dealWithNoOxException(Exception $oEx)
130  {
131  if (0 != $this->_iDebug) {
132  $sLogMsg = date('Y-m-d H:i:s') . $oEx . "\n---------------------------------------------\n";
133  //deprecated since v5.3 (2016-06-17); Logging mechanism will be changed in 6.0.
134  oxRegistry::getUtils()->writeToLog($sLogMsg, $this->getLogFileName());
135  //end deprecated
136  if (defined('OXID_PHP_UNIT')) {
137  return;
138  } elseif (0 != $this->_iDebug) {
139  oxRegistry::getUtils()->showMessageAndExit($sLogMsg);
140  }
141  }
142 
143  try {
144  oxRegistry::getUtils()->redirectOffline(500);
145  } catch (Exception $oException) {
146  }
147 
148  exit();
149  }
150 
162  public function __call($sMethod, $aArgs)
163  {
164  if (defined('OXID_PHP_UNIT')) {
165  if (substr($sMethod, 0, 4) == "UNIT") {
166  $sMethod = str_replace("UNIT", "_", $sMethod);
167  }
168  if (method_exists($this, $sMethod)) {
169  return call_user_func_array(array(& $this, $sMethod), $aArgs);
170  }
171  }
172 
173  throw new oxSystemComponentException("Function '$sMethod' does not exist or is not accessible! (" . __CLASS__ . ")" . PHP_EOL);
174  }
175 }