2022-08-16 11:08:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* https://www.d3data.de
|
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
|
|
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
|
|
|
* @link https://www.oxidmodule.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace D3\DebugBar\Core;
|
|
|
|
|
2022-08-17 00:20:20 +02:00
|
|
|
use D3\DebugBar\Application\Models\AvailabilityCheck;
|
2022-08-16 11:08:05 +02:00
|
|
|
use D3\DebugBar\Application\Models\Exceptions\CompileErrorException;
|
|
|
|
use D3\DebugBar\Application\Models\Exceptions\CoreErrorException;
|
|
|
|
use D3\DebugBar\Application\Models\Exceptions\ParseException;
|
|
|
|
use D3\DebugBar\Application\Models\Exceptions\UserErrorException;
|
|
|
|
use ErrorException;
|
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
|
|
|
|
|
|
|
class DebugBarErrorHandler
|
|
|
|
{
|
|
|
|
/**
|
2022-08-16 11:08:53 +02:00
|
|
|
* @param int $severity
|
|
|
|
* @param string $message
|
|
|
|
* @param string $file
|
|
|
|
* @param int $line
|
2022-08-16 11:08:05 +02:00
|
|
|
*
|
|
|
|
* @return void|false
|
|
|
|
* @throws CompileErrorException
|
|
|
|
* @throws CoreErrorException
|
|
|
|
* @throws ErrorException
|
|
|
|
* @throws ParseException
|
|
|
|
* @throws UserErrorException
|
|
|
|
*/
|
2022-08-16 11:08:53 +02:00
|
|
|
public function callback(int $severity, string $message, string $file, int $line)
|
2022-08-16 11:08:05 +02:00
|
|
|
{
|
2022-08-17 00:20:20 +02:00
|
|
|
AvailabilityCheck::markErrorOccured();
|
2022-08-16 11:08:05 +02:00
|
|
|
|
2022-08-16 11:08:53 +02:00
|
|
|
if (0 === error_reporting() || !(error_reporting() & $severity)) {
|
2022-08-16 11:08:05 +02:00
|
|
|
// This error code is not included in error_reporting.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-08-16 11:08:53 +02:00
|
|
|
$smartyTemplate = $this->getSmartyTemplateLocationFromError($message);
|
|
|
|
if (is_array($smartyTemplate)) {
|
2022-08-16 11:08:05 +02:00
|
|
|
[ $file, $line ] = $smartyTemplate;
|
|
|
|
}
|
|
|
|
|
2022-08-16 11:08:53 +02:00
|
|
|
switch ($severity) {
|
2022-08-16 11:08:05 +02:00
|
|
|
case E_CORE_ERROR:
|
|
|
|
throw new CoreErrorException($message, 0, $severity, $file, $line);
|
|
|
|
case E_COMPILE_ERROR:
|
|
|
|
throw new CompileErrorException($message, 0, $severity, $file, $line);
|
|
|
|
case E_USER_ERROR:
|
|
|
|
throw new UserErrorException($message, 0, $severity, $file, $line);
|
|
|
|
case E_PARSE:
|
|
|
|
throw new ParseException($message, 0, $severity, $file, $line);
|
|
|
|
case E_ERROR:
|
|
|
|
throw new ErrorException($message, 0, $severity, $file, $line);
|
|
|
|
default:
|
|
|
|
$this->handleUnregisteredErrorTypes($message, $severity, $file, $line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-08-16 11:08:53 +02:00
|
|
|
* @param string $messsage
|
2022-08-16 11:08:05 +02:00
|
|
|
* @return array|null
|
|
|
|
*/
|
2022-08-16 11:08:53 +02:00
|
|
|
protected function getSmartyTemplateLocationFromError(string $messsage): ?array
|
2022-08-16 11:08:05 +02:00
|
|
|
{
|
|
|
|
if (stristr($messsage, 'Smarty error: [in ')) {
|
|
|
|
$start = strpos($messsage, '[')+1;
|
|
|
|
$end = strpos($messsage, ']');
|
|
|
|
$parts = explode(' ', substr($messsage, $start, $end - $start));
|
|
|
|
return [Registry::getConfig()->getTemplateDir(isAdmin()).$parts[1], (int) $parts[3]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-08-16 11:08:53 +02:00
|
|
|
* @param string $message
|
|
|
|
* @param int $severity
|
|
|
|
* @param string $file
|
|
|
|
* @param int $line
|
|
|
|
* @return void
|
2022-08-16 11:08:05 +02:00
|
|
|
*
|
|
|
|
* @throws ErrorException
|
|
|
|
*/
|
2022-08-16 11:08:53 +02:00
|
|
|
protected function handleUnregisteredErrorTypes(
|
|
|
|
string $message = '',
|
|
|
|
int $severity = 1,
|
|
|
|
string $file = __FILE__,
|
|
|
|
int $line = __LINE__
|
|
|
|
): void {
|
2022-08-16 11:08:05 +02:00
|
|
|
throw new ErrorException($message, 0, $severity, $file, $line);
|
|
|
|
}
|
2022-08-16 11:08:53 +02:00
|
|
|
}
|