Mercurial > hg > isophonics-drupal-site
diff vendor/symfony/debug/ErrorHandler.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | c2387f117808 |
children | af1871eacc83 |
line wrap: on
line diff
--- a/vendor/symfony/debug/ErrorHandler.php Tue Jul 10 15:07:59 2018 +0100 +++ b/vendor/symfony/debug/ErrorHandler.php Thu Feb 28 13:21:36 2019 +0000 @@ -11,17 +11,17 @@ namespace Symfony\Component\Debug; +use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; -use Psr\Log\LoggerInterface; use Symfony\Component\Debug\Exception\ContextErrorException; use Symfony\Component\Debug\Exception\FatalErrorException; use Symfony\Component\Debug\Exception\FatalThrowableError; use Symfony\Component\Debug\Exception\OutOfMemoryException; use Symfony\Component\Debug\Exception\SilencedErrorContext; +use Symfony\Component\Debug\FatalErrorHandler\ClassNotFoundFatalErrorHandler; +use Symfony\Component\Debug\FatalErrorHandler\FatalErrorHandlerInterface; use Symfony\Component\Debug\FatalErrorHandler\UndefinedFunctionFatalErrorHandler; use Symfony\Component\Debug\FatalErrorHandler\UndefinedMethodFatalErrorHandler; -use Symfony\Component\Debug\FatalErrorHandler\ClassNotFoundFatalErrorHandler; -use Symfony\Component\Debug\FatalErrorHandler\FatalErrorHandlerInterface; /** * A generic ErrorHandler for the PHP engine. @@ -48,7 +48,7 @@ */ class ErrorHandler { - private $levels = array( + private $levels = [ E_DEPRECATED => 'Deprecated', E_USER_DEPRECATED => 'User Deprecated', E_NOTICE => 'Notice', @@ -64,25 +64,25 @@ E_PARSE => 'Parse Error', E_ERROR => 'Error', E_CORE_ERROR => 'Core Error', - ); + ]; - private $loggers = array( - E_DEPRECATED => array(null, LogLevel::INFO), - E_USER_DEPRECATED => array(null, LogLevel::INFO), - E_NOTICE => array(null, LogLevel::WARNING), - E_USER_NOTICE => array(null, LogLevel::WARNING), - E_STRICT => array(null, LogLevel::WARNING), - E_WARNING => array(null, LogLevel::WARNING), - E_USER_WARNING => array(null, LogLevel::WARNING), - E_COMPILE_WARNING => array(null, LogLevel::WARNING), - E_CORE_WARNING => array(null, LogLevel::WARNING), - E_USER_ERROR => array(null, LogLevel::CRITICAL), - E_RECOVERABLE_ERROR => array(null, LogLevel::CRITICAL), - E_COMPILE_ERROR => array(null, LogLevel::CRITICAL), - E_PARSE => array(null, LogLevel::CRITICAL), - E_ERROR => array(null, LogLevel::CRITICAL), - E_CORE_ERROR => array(null, LogLevel::CRITICAL), - ); + private $loggers = [ + E_DEPRECATED => [null, LogLevel::INFO], + E_USER_DEPRECATED => [null, LogLevel::INFO], + E_NOTICE => [null, LogLevel::WARNING], + E_USER_NOTICE => [null, LogLevel::WARNING], + E_STRICT => [null, LogLevel::WARNING], + E_WARNING => [null, LogLevel::WARNING], + E_USER_WARNING => [null, LogLevel::WARNING], + E_COMPILE_WARNING => [null, LogLevel::WARNING], + E_CORE_WARNING => [null, LogLevel::WARNING], + E_USER_ERROR => [null, LogLevel::CRITICAL], + E_RECOVERABLE_ERROR => [null, LogLevel::CRITICAL], + E_COMPILE_ERROR => [null, LogLevel::CRITICAL], + E_PARSE => [null, LogLevel::CRITICAL], + E_ERROR => [null, LogLevel::CRITICAL], + E_CORE_ERROR => [null, LogLevel::CRITICAL], + ]; private $thrownErrors = 0x1FFF; // E_ALL - E_DEPRECATED - E_USER_DEPRECATED private $scopedErrors = 0x1FFF; // E_ALL - E_DEPRECATED - E_USER_DEPRECATED @@ -97,10 +97,10 @@ private $bootstrappingLogger; private static $reservedMemory; - private static $stackedErrors = array(); - private static $stackedErrorLevels = array(); + private static $stackedErrors = []; + private static $stackedErrorLevels = []; private static $toStringException = null; - private static $silencedErrorCache = array(); + private static $silencedErrorCache = []; private static $silencedErrorCount = 0; private static $exitCode = 0; @@ -123,29 +123,29 @@ $handler = new static(); } - if (null === $prev = set_error_handler(array($handler, 'handleError'))) { + if (null === $prev = set_error_handler([$handler, 'handleError'])) { restore_error_handler(); // Specifying the error types earlier would expose us to https://bugs.php.net/63206 - set_error_handler(array($handler, 'handleError'), $handler->thrownErrors | $handler->loggedErrors); + set_error_handler([$handler, 'handleError'], $handler->thrownErrors | $handler->loggedErrors); $handler->isRoot = true; } - if ($handlerIsNew && is_array($prev) && $prev[0] instanceof self) { + if ($handlerIsNew && \is_array($prev) && $prev[0] instanceof self) { $handler = $prev[0]; $replace = false; } if (!$replace && $prev) { restore_error_handler(); - $handlerIsRegistered = is_array($prev) && $handler === $prev[0]; + $handlerIsRegistered = \is_array($prev) && $handler === $prev[0]; } else { $handlerIsRegistered = true; } - if (is_array($prev = set_exception_handler(array($handler, 'handleException'))) && $prev[0] instanceof self) { + if (\is_array($prev = set_exception_handler([$handler, 'handleException'])) && $prev[0] instanceof self) { restore_exception_handler(); if (!$handlerIsRegistered) { $handler = $prev[0]; } elseif ($handler !== $prev[0] && $replace) { - set_exception_handler(array($handler, 'handleException')); + set_exception_handler([$handler, 'handleException']); $p = $prev[0]->setExceptionHandler(null); $handler->setExceptionHandler($p); $prev[0]->setExceptionHandler($p); @@ -178,12 +178,12 @@ */ public function setDefaultLogger(LoggerInterface $logger, $levels = E_ALL, $replace = false) { - $loggers = array(); + $loggers = []; - if (is_array($levels)) { + if (\is_array($levels)) { foreach ($levels as $type => $logLevel) { if (empty($this->loggers[$type][0]) || $replace || $this->loggers[$type][0] === $this->bootstrappingLogger) { - $loggers[$type] = array($logger, $logLevel); + $loggers[$type] = [$logger, $logLevel]; } } } else { @@ -214,14 +214,14 @@ { $prevLogged = $this->loggedErrors; $prev = $this->loggers; - $flush = array(); + $flush = []; foreach ($loggers as $type => $log) { if (!isset($prev[$type])) { throw new \InvalidArgumentException('Unknown error type: '.$type); } - if (!is_array($log)) { - $log = array($log); + if (!\is_array($log)) { + $log = [$log]; } elseif (!array_key_exists(0, $log)) { throw new \InvalidArgumentException('No logger provided'); } @@ -353,14 +353,14 @@ { if ($prev !== $this->thrownErrors | $this->loggedErrors) { $handler = set_error_handler('var_dump'); - $handler = is_array($handler) ? $handler[0] : null; + $handler = \is_array($handler) ? $handler[0] : null; restore_error_handler(); if ($handler === $this) { restore_error_handler(); if ($this->isRoot) { - set_error_handler(array($this, 'handleError'), $this->thrownErrors | $this->loggedErrors); + set_error_handler([$this, 'handleError'], $this->thrownErrors | $this->loggedErrors); } else { - set_error_handler(array($this, 'handleError')); + set_error_handler([$this, 'handleError']); } } } @@ -396,11 +396,11 @@ } $scope = $this->scopedErrors & $type; - if (4 < $numArgs = func_num_args()) { - $context = $scope ? (func_get_arg(4) ?: array()) : array(); + if (4 < $numArgs = \func_num_args()) { + $context = $scope ? (func_get_arg(4) ?: []) : []; $backtrace = 5 < $numArgs ? func_get_arg(5) : null; // defined on HHVM } else { - $context = array(); + $context = []; $backtrace = null; } @@ -426,19 +426,19 @@ self::$toStringException = null; } elseif (!$throw && !($type & $level)) { if (!isset(self::$silencedErrorCache[$id = $file.':'.$line])) { - $lightTrace = $this->tracedErrors & $type ? $this->cleanTrace(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3), $type, $file, $line, false) : array(); + $lightTrace = $this->tracedErrors & $type ? $this->cleanTrace(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3), $type, $file, $line, false) : []; $errorAsException = new SilencedErrorContext($type, $file, $line, $lightTrace); } elseif (isset(self::$silencedErrorCache[$id][$message])) { $lightTrace = null; $errorAsException = self::$silencedErrorCache[$id][$message]; ++$errorAsException->count; } else { - $lightTrace = array(); + $lightTrace = []; $errorAsException = null; } if (100 < ++self::$silencedErrorCount) { - self::$silencedErrorCache = $lightTrace = array(); + self::$silencedErrorCache = $lightTrace = []; self::$silencedErrorCount = 1; } if ($errorAsException) { @@ -460,7 +460,7 @@ $lightTrace = $this->cleanTrace($backtrace, $type, $file, $line, $throw); $this->traceReflector->setValue($errorAsException, $lightTrace); } else { - $this->traceReflector->setValue($errorAsException, array()); + $this->traceReflector->setValue($errorAsException, []); } } @@ -510,19 +510,23 @@ if ($this->isRecursive) { $log = 0; } elseif (self::$stackedErrorLevels) { - self::$stackedErrors[] = array( + self::$stackedErrors[] = [ $this->loggers[$type][0], ($type & $level) ? $this->loggers[$type][1] : LogLevel::DEBUG, $logMessage, - $errorAsException ? array('exception' => $errorAsException) : array(), - ); + $errorAsException ? ['exception' => $errorAsException] : [], + ]; } else { try { $this->isRecursive = true; $level = ($type & $level) ? $this->loggers[$type][1] : LogLevel::DEBUG; - $this->loggers[$type][0]->log($level, $logMessage, $errorAsException ? array('exception' => $errorAsException) : array()); + $this->loggers[$type][0]->log($level, $logMessage, $errorAsException ? ['exception' => $errorAsException] : []); } finally { $this->isRecursive = false; + + if (!\defined('HHVM_VERSION')) { + set_error_handler([$this, __FUNCTION__]); + } } } @@ -551,12 +555,12 @@ if (($this->loggedErrors & $type) || $exception instanceof FatalThrowableError) { if ($exception instanceof FatalErrorException) { if ($exception instanceof FatalThrowableError) { - $error = array( + $error = [ 'type' => $type, 'message' => $message = $exception->getMessage(), 'file' => $exception->getFile(), 'line' => $exception->getLine(), - ); + ]; } else { $message = 'Fatal '.$exception->getMessage(); } @@ -568,7 +572,7 @@ } if ($this->loggedErrors & $type) { try { - $this->loggers[$type][0]->log($this->loggers[$type][1], $message, array('exception' => $exception)); + $this->loggers[$type][0]->log($this->loggers[$type][1], $message, ['exception' => $exception]); } catch (\Exception $handlerException) { } catch (\Throwable $handlerException) { } @@ -612,11 +616,11 @@ } $handler = self::$reservedMemory = null; - $handlers = array(); + $handlers = []; $previousHandler = null; $sameHandlerLimit = 10; - while (!is_array($handler) || !$handler[0] instanceof self) { + while (!\is_array($handler) || !$handler[0] instanceof self) { $handler = set_exception_handler('var_dump'); restore_exception_handler(); @@ -643,7 +647,7 @@ $handler[0]->setExceptionHandler($h); } $handler = $handler[0]; - $handlers = array(); + $handlers = []; if ($exit = null === $error) { $error = error_get_last(); @@ -727,7 +731,7 @@ if (empty(self::$stackedErrorLevels)) { $errors = self::$stackedErrors; - self::$stackedErrors = array(); + self::$stackedErrors = []; foreach ($errors as $error) { $error[0]->log($error[1], $error[2], $error[3]); @@ -744,11 +748,11 @@ */ protected function getFatalErrorHandlers() { - return array( + return [ new UndefinedFunctionFatalErrorHandler(), new UndefinedMethodFatalErrorHandler(), new ClassNotFoundFatalErrorHandler(), - ); + ]; } private function cleanTrace($backtrace, $type, $file, $line, $throw) @@ -757,7 +761,7 @@ for ($i = 0; isset($backtrace[$i]); ++$i) { if (isset($backtrace[$i]['file'], $backtrace[$i]['line']) && $backtrace[$i]['line'] === $line && $backtrace[$i]['file'] === $file) { - $lightTrace = array_slice($lightTrace, 1 + $i); + $lightTrace = \array_slice($lightTrace, 1 + $i); break; } }