X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fsymfony%2Fdebug%2FExceptionHandler.php;fp=vendor%2Fsymfony%2Fdebug%2FExceptionHandler.php;h=97470cb6b4d01ae8e7f2bb1efe24a572407a5feb;hp=0ac644ef0eb46c32636ab678fcf33c9215c172f7;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/vendor/symfony/debug/ExceptionHandler.php b/vendor/symfony/debug/ExceptionHandler.php index 0ac644ef0..97470cb6b 100644 --- a/vendor/symfony/debug/ExceptionHandler.php +++ b/vendor/symfony/debug/ExceptionHandler.php @@ -11,9 +11,9 @@ namespace Symfony\Component\Debug; -use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Debug\Exception\FlattenException; use Symfony\Component\Debug\Exception\OutOfMemoryException; +use Symfony\Component\HttpKernel\Debug\FileLinkFormatter; /** * ExceptionHandler converts an exception to a Response object. @@ -38,14 +38,6 @@ class ExceptionHandler public function __construct($debug = true, $charset = null, $fileLinkFormat = null) { - if (false !== strpos($charset, '%')) { - @trigger_error('Providing $fileLinkFormat as second argument to '.__METHOD__.' is deprecated since version 2.8 and will be unsupported in 3.0. Please provide it as third argument, after $charset.', E_USER_DEPRECATED); - - // Swap $charset and $fileLinkFormat for BC reasons - $pivot = $fileLinkFormat; - $fileLinkFormat = $charset; - $charset = $pivot; - } $this->debug = $debug; $this->charset = $charset ?: ini_get('default_charset') ?: 'UTF-8'; $this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format'); @@ -80,11 +72,8 @@ class ExceptionHandler * * @return callable|null The previous exception handler if any */ - public function setHandler($handler) + public function setHandler(callable $handler = null) { - if (null !== $handler && !is_callable($handler)) { - throw new \LogicException('The exception handler must be a valid PHP callable.'); - } $old = $this->handler; $this->handler = $handler; @@ -94,14 +83,14 @@ class ExceptionHandler /** * Sets the format for links to source files. * - * @param string $format The format for links to source files + * @param string|FileLinkFormatter $fileLinkFormat The format for links to source files * * @return string The previous file link format */ - public function setFileLinkFormat($format) + public function setFileLinkFormat($fileLinkFormat) { $old = $this->fileLinkFormat; - $this->fileLinkFormat = $format; + $this->fileLinkFormat = $fileLinkFormat; return $old; } @@ -117,20 +106,36 @@ class ExceptionHandler public function handle(\Exception $exception) { if (null === $this->handler || $exception instanceof OutOfMemoryException) { - $this->failSafeHandle($exception); + $this->sendPhpResponse($exception); return; } $caughtLength = $this->caughtLength = 0; - ob_start(array($this, 'catchOutput')); - $this->failSafeHandle($exception); + ob_start(function ($buffer) { + $this->caughtBuffer = $buffer; + + return ''; + }); + + $this->sendPhpResponse($exception); while (null === $this->caughtBuffer && ob_end_flush()) { // Empty loop, everything is in the condition } if (isset($this->caughtBuffer[0])) { - ob_start(array($this, 'cleanOutput')); + ob_start(function ($buffer) { + if ($this->caughtLength) { + // use substr_replace() instead of substr() for mbstring overloading resistance + $cleanBuffer = substr_replace($buffer, '', 0, $this->caughtLength); + if (isset($cleanBuffer[0])) { + $buffer = $cleanBuffer; + } + } + + return $buffer; + }); + echo $this->caughtBuffer; $caughtLength = ob_get_length(); } @@ -147,33 +152,6 @@ class ExceptionHandler } } - /** - * Sends a response for the given Exception. - * - * If you have the Symfony HttpFoundation component installed, - * this method will use it to create and send the response. If not, - * it will fallback to plain PHP functions. - * - * @param \Exception $exception An \Exception instance - */ - private function failSafeHandle(\Exception $exception) - { - if (class_exists('Symfony\Component\HttpFoundation\Response', false) - && __CLASS__ !== get_class($this) - && ($reflector = new \ReflectionMethod($this, 'createResponse')) - && __CLASS__ !== $reflector->class - ) { - $response = $this->createResponse($exception); - $response->sendHeaders(); - $response->sendContent(); - @trigger_error(sprintf("The %s::createResponse method is deprecated since 2.8 and won't be called anymore when handling an exception in 3.0.", $reflector->class), E_USER_DEPRECATED); - - return; - } - - $this->sendPhpResponse($exception); - } - /** * Sends the error associated with the given Exception as a plain PHP response. * @@ -199,26 +177,6 @@ class ExceptionHandler echo $this->decorate($this->getContent($exception), $this->getStylesheet($exception)); } - /** - * Creates the error Response associated with the given Exception. - * - * @param \Exception|FlattenException $exception An \Exception or FlattenException instance - * - * @return Response A Response instance - * - * @deprecated since 2.8, to be removed in 3.0. - */ - public function createResponse($exception) - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); - - if (!$exception instanceof FlattenException) { - $exception = FlattenException::create($exception); - } - - return Response::create($this->getHtml($exception), $exception->getStatusCode(), $exception->getHeaders())->setCharset($this->charset); - } - /** * Gets the full HTML content associated with the given exception. * @@ -238,8 +196,6 @@ class ExceptionHandler /** * Gets the HTML content associated with the given exception. * - * @param FlattenException $exception A FlattenException instance - * * @return string The content as a string */ public function getContent(FlattenException $exception) @@ -262,28 +218,30 @@ class ExceptionHandler $class = $this->formatClass($e['class']); $message = nl2br($this->escapeHtml($e['message'])); $content .= sprintf(<<<'EOF' -

- %d/%d - %s%s: - %s -

-
-
    - +
    + + + EOF - , $ind, $total, $class, $this->formatPath($e['trace'][0]['file'], $e['trace'][0]['line']), $message); + , $ind, $total, $class, $message); foreach ($e['trace'] as $trace) { - $content .= '
  1. '; + $content .= '
  2. \n"; } - $content .= " \n\n"; + $content .= "\n
    +

    + (%d/%d) + %s +

    +

    %s

    +
    '; if ($trace['function']) { - $content .= sprintf('at %s%s%s(%s)', $this->formatClass($trace['class']), $trace['type'], $trace['function'], $this->formatArgs($trace['args'])); + $content .= sprintf('at %s%s%s(%s)', $this->formatClass($trace['class']), $trace['type'], $trace['function'], $this->formatArgs($trace['args'])); } if (isset($trace['file']) && isset($trace['line'])) { $content .= $this->formatPath($trace['file'], $trace['line']); } - $content .= "\n"; + $content .= "
    \n
    \n"; } } catch (\Exception $e) { // something nasty happened and we cannot throw an exception anymore @@ -295,9 +253,19 @@ EOF } } + $symfonyGhostImageContents = $this->getSymfonyGhostAsSvg(); + return << -

    $title

    +
    +
    +
    +

    $title

    +
    $symfonyGhostImageContents
    +
    +
    +
    + +
    $content
    EOF; @@ -306,65 +274,56 @@ EOF; /** * Gets the stylesheet associated with the given exception. * - * @param FlattenException $exception A FlattenException instance - * * @return string The stylesheet as a string */ public function getStylesheet(FlattenException $exception) { return <<<'EOF' - .sf-reset { font: 11px Verdana, Arial, sans-serif; color: #333 } - .sf-reset .clear { clear:both; height:0; font-size:0; line-height:0; } - .sf-reset .clear_fix:after { display:block; height:0; clear:both; visibility:hidden; } - .sf-reset .clear_fix { display:inline-block; } - .sf-reset * html .clear_fix { height:1%; } - .sf-reset .clear_fix { display:block; } - .sf-reset, .sf-reset .block { margin: auto } - .sf-reset abbr { border-bottom: 1px dotted #000; cursor: help; } - .sf-reset p { font-size:14px; line-height:20px; color:#868686; padding-bottom:20px } - .sf-reset strong { font-weight:bold; } - .sf-reset a { color:#6c6159; cursor: default; } - .sf-reset a img { border:none; } - .sf-reset a:hover { text-decoration:underline; } - .sf-reset em { font-style:italic; } - .sf-reset h1, .sf-reset h2 { font: 20px Georgia, "Times New Roman", Times, serif } - .sf-reset .exception_counter { background-color: #fff; color: #333; padding: 6px; float: left; margin-right: 10px; float: left; display: block; } - .sf-reset .exception_title { margin-left: 3em; margin-bottom: 0.7em; display: block; } - .sf-reset .exception_message { margin-left: 3em; display: block; } - .sf-reset .traces li { font-size:12px; padding: 2px 4px; list-style-type:decimal; margin-left:20px; } - .sf-reset .block { background-color:#FFFFFF; padding:10px 28px; margin-bottom:20px; - -webkit-border-bottom-right-radius: 16px; - -webkit-border-bottom-left-radius: 16px; - -moz-border-radius-bottomright: 16px; - -moz-border-radius-bottomleft: 16px; - border-bottom-right-radius: 16px; - border-bottom-left-radius: 16px; - border-bottom:1px solid #ccc; - border-right:1px solid #ccc; - border-left:1px solid #ccc; - word-wrap: break-word; - } - .sf-reset .block_exception { background-color:#ddd; color: #333; padding:20px; - -webkit-border-top-left-radius: 16px; - -webkit-border-top-right-radius: 16px; - -moz-border-radius-topleft: 16px; - -moz-border-radius-topright: 16px; - border-top-left-radius: 16px; - border-top-right-radius: 16px; - border-top:1px solid #ccc; - border-right:1px solid #ccc; - border-left:1px solid #ccc; - overflow: hidden; - word-wrap: break-word; - } - .sf-reset a { background:none; color:#868686; text-decoration:none; } - .sf-reset a:hover { background:none; color:#313131; text-decoration:underline; } - .sf-reset ol { padding: 10px 0; } - .sf-reset h1 { background-color:#FFFFFF; padding: 15px 28px; margin-bottom: 20px; - -webkit-border-radius: 10px; - -moz-border-radius: 10px; - border-radius: 10px; - border: 1px solid #ccc; + body { background-color: #F9F9F9; color: #222; font: 14px/1.4 Helvetica, Arial, sans-serif; margin: 0; padding-bottom: 45px; } + + a { cursor: pointer; text-decoration: none; } + a:hover { text-decoration: underline; } + abbr[title] { border-bottom: none; cursor: help; text-decoration: none; } + + code, pre { font: 13px/1.5 Consolas, Monaco, Menlo, "Ubuntu Mono", "Liberation Mono", monospace; } + + table, tr, th, td { background: #FFF; border-collapse: collapse; vertical-align: top; } + table { background: #FFF; border: 1px solid #E0E0E0; box-shadow: 0px 0px 1px rgba(128, 128, 128, .2); margin: 1em 0; width: 100%; } + table th, table td { border: solid #E0E0E0; border-width: 1px 0; padding: 8px 10px; } + table th { background-color: #E0E0E0; font-weight: bold; text-align: left; } + + .hidden-xs-down { display: none; } + .block { display: block; } + .break-long-words { -ms-word-break: break-all; word-break: break-all; word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; } + .text-muted { color: #999; } + + .container { max-width: 1024px; margin: 0 auto; padding: 0 15px; } + .container::after { content: ""; display: table; clear: both; } + + .exception-summary { background: #B0413E; border-bottom: 2px solid rgba(0, 0, 0, 0.1); border-top: 1px solid rgba(0, 0, 0, .3); flex: 0 0 auto; margin-bottom: 30px; } + + .exception-message-wrapper { display: flex; align-items: center; min-height: 70px; } + .exception-message { flex-grow: 1; padding: 30px 0; } + .exception-message, .exception-message a { color: #FFF; font-size: 21px; font-weight: 400; margin: 0; } + .exception-message.long { font-size: 18px; } + .exception-message a { border-bottom: 1px solid rgba(255, 255, 255, 0.5); font-size: inherit; text-decoration: none; } + .exception-message a:hover { border-bottom-color: #ffffff; } + + .exception-illustration { flex-basis: 111px; flex-shrink: 0; height: 66px; margin-left: 15px; opacity: .7; } + + .trace + .trace { margin-top: 30px; } + .trace-head .trace-class { color: #222; font-size: 18px; font-weight: bold; line-height: 1.3; margin: 0; position: relative; } + + .trace-message { font-size: 14px; font-weight: normal; margin: .5em 0 0; } + + .trace-file-path, .trace-file-path a { color: #222; margin-top: 3px; font-size: 13px; } + .trace-class { color: #B0413E; } + .trace-type { padding: 0 2px; } + .trace-method { color: #B0413E; font-weight: bold; } + .trace-arguments { color: #777; font-weight: normal; padding-left: 2px; } + + @media (min-width: 575px) { + .hidden-xs-down { display: initial; } } EOF; } @@ -377,15 +336,7 @@ EOF; - + $content @@ -403,16 +354,14 @@ EOF; private function formatPath($path, $line) { - $path = $this->escapeHtml($path); - $file = preg_match('#[^/\\\\]*$#', $path, $file) ? $file[0] : $path; + $file = $this->escapeHtml(preg_match('#[^/\\\\]*+$#', $path, $file) ? $file[0] : $path); + $fmt = $this->fileLinkFormat; - if ($linkFormat = $this->fileLinkFormat) { - $link = strtr($this->escapeHtml($linkFormat), array('%f' => $path, '%l' => (int) $line)); - - return sprintf(' in %s line %d', $link, $file, $line); + if ($fmt && $link = is_string($fmt) ? strtr($fmt, array('%f' => $path, '%l' => $line)) : $fmt->format($path, $line)) { + return sprintf('in %s (line %d)', $this->escapeHtml($link), $file, $line); } - return sprintf(' in %s line %d', $path, $file, $line); + return sprintf('in %s (line %d)', $this->escapeHtml($path), $file, $line); } /** @@ -430,8 +379,6 @@ EOF; $formattedValue = sprintf('object(%s)', $this->formatClass($item[1])); } elseif ('array' === $item[0]) { $formattedValue = sprintf('array(%s)', is_array($item[1]) ? $this->formatArgs($item[1]) : $item[1]); - } elseif ('string' === $item[0]) { - $formattedValue = sprintf("'%s'", $this->escapeHtml($item[1])); } elseif ('null' === $item[0]) { $formattedValue = 'null'; } elseif ('boolean' === $item[0]) { @@ -439,58 +386,25 @@ EOF; } elseif ('resource' === $item[0]) { $formattedValue = 'resource'; } else { - $formattedValue = str_replace("\n", '', var_export($this->escapeHtml((string) $item[1]), true)); + $formattedValue = str_replace("\n", '', $this->escapeHtml(var_export($item[1], true))); } - $result[] = is_int($key) ? $formattedValue : sprintf("'%s' => %s", $key, $formattedValue); + $result[] = is_int($key) ? $formattedValue : sprintf("'%s' => %s", $this->escapeHtml($key), $formattedValue); } return implode(', ', $result); } - /** - * Returns an UTF-8 and HTML encoded string. - * - * @deprecated since version 2.7, to be removed in 3.0. - */ - protected static function utf8Htmlize($str) - { - @trigger_error('The '.__METHOD__.' method is deprecated since version 2.7 and will be removed in 3.0.', E_USER_DEPRECATED); - - return htmlspecialchars($str, ENT_QUOTES | (\PHP_VERSION_ID >= 50400 ? ENT_SUBSTITUTE : 0), 'UTF-8'); - } - /** * HTML-encodes a string. */ private function escapeHtml($str) { - return htmlspecialchars($str, ENT_QUOTES | (\PHP_VERSION_ID >= 50400 ? ENT_SUBSTITUTE : 0), $this->charset); + return htmlspecialchars($str, ENT_COMPAT | ENT_SUBSTITUTE, $this->charset); } - /** - * @internal - */ - public function catchOutput($buffer) + private function getSymfonyGhostAsSvg() { - $this->caughtBuffer = $buffer; - - return ''; - } - - /** - * @internal - */ - public function cleanOutput($buffer) - { - if ($this->caughtLength) { - // use substr_replace() instead of substr() for mbstring overloading resistance - $cleanBuffer = substr_replace($buffer, '', 0, $this->caughtLength); - if (isset($cleanBuffer[0])) { - $buffer = $cleanBuffer; - } - } - - return $buffer; + return ''; } }