diff vendor/symfony/debug/ExceptionHandler.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/ExceptionHandler.php	Tue Jul 10 15:07:59 2018 +0100
+++ b/vendor/symfony/debug/ExceptionHandler.php	Thu Feb 28 13:21:36 2019 +0000
@@ -56,10 +56,10 @@
     {
         $handler = new static($debug, $charset, $fileLinkFormat);
 
-        $prev = set_exception_handler(array($handler, 'handle'));
-        if (is_array($prev) && $prev[0] instanceof ErrorHandler) {
+        $prev = set_exception_handler([$handler, 'handle']);
+        if (\is_array($prev) && $prev[0] instanceof ErrorHandler) {
             restore_exception_handler();
-            $prev[0]->setExceptionHandler(array($handler, 'handle'));
+            $prev[0]->setExceptionHandler([$handler, 'handle']);
         }
 
         return $handler;
@@ -142,7 +142,7 @@
         $this->caughtBuffer = null;
 
         try {
-            call_user_func($this->handler, $exception);
+            \call_user_func($this->handler, $exception);
             $this->caughtLength = $caughtLength;
         } catch (\Exception $e) {
             if (!$caughtLength) {
@@ -208,48 +208,54 @@
                 $title = 'Whoops, looks like something went wrong.';
         }
 
+        if (!$this->debug) {
+            return <<<EOF
+                <div class="container">
+                    <h1>$title</h1>
+                </div>
+EOF;
+        }
+
         $content = '';
-        if ($this->debug) {
-            try {
-                $count = count($exception->getAllPrevious());
-                $total = $count + 1;
-                foreach ($exception->toArray() as $position => $e) {
-                    $ind = $count - $position + 1;
-                    $class = $this->formatClass($e['class']);
-                    $message = nl2br($this->escapeHtml($e['message']));
-                    $content .= sprintf(<<<'EOF'
-                        <div class="trace trace-as-html">
-                            <table class="trace-details">
-                                <thead class="trace-head"><tr><th>
-                                    <h3 class="trace-class">
-                                        <span class="text-muted">(%d/%d)</span>
-                                        <span class="exception_title">%s</span>
-                                    </h3>
-                                    <p class="break-long-words trace-message">%s</p>
-                                </th></tr></thead>
-                                <tbody>
+        try {
+            $count = \count($exception->getAllPrevious());
+            $total = $count + 1;
+            foreach ($exception->toArray() as $position => $e) {
+                $ind = $count - $position + 1;
+                $class = $this->formatClass($e['class']);
+                $message = nl2br($this->escapeHtml($e['message']));
+                $content .= sprintf(<<<'EOF'
+                    <div class="trace trace-as-html">
+                        <table class="trace-details">
+                            <thead class="trace-head"><tr><th>
+                                <h3 class="trace-class">
+                                    <span class="text-muted">(%d/%d)</span>
+                                    <span class="exception_title">%s</span>
+                                </h3>
+                                <p class="break-long-words trace-message">%s</p>
+                            </th></tr></thead>
+                            <tbody>
 EOF
-                        , $ind, $total, $class, $message);
-                    foreach ($e['trace'] as $trace) {
-                        $content .= '<tr><td>';
-                        if ($trace['function']) {
-                            $content .= sprintf('at <span class="trace-class">%s</span><span class="trace-type">%s</span><span class="trace-method">%s</span>(<span class="trace-arguments">%s</span>)', $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 .= "</td></tr>\n";
+                    , $ind, $total, $class, $message);
+                foreach ($e['trace'] as $trace) {
+                    $content .= '<tr><td>';
+                    if ($trace['function']) {
+                        $content .= sprintf('at <span class="trace-class">%s</span><span class="trace-type">%s</span><span class="trace-method">%s</span>(<span class="trace-arguments">%s</span>)', $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 .= "</td></tr>\n";
+                }
 
-                    $content .= "</tbody>\n</table>\n</div>\n";
-                }
-            } catch (\Exception $e) {
-                // something nasty happened and we cannot throw an exception anymore
-                if ($this->debug) {
-                    $title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $this->escapeHtml($e->getMessage()));
-                } else {
-                    $title = 'Whoops, looks like something went wrong.';
-                }
+                $content .= "</tbody>\n</table>\n</div>\n";
+            }
+        } catch (\Exception $e) {
+            // something nasty happened and we cannot throw an exception anymore
+            if ($this->debug) {
+                $title = sprintf('Exception thrown when handling an exception (%s: %s)', \get_class($e), $this->escapeHtml($e->getMessage()));
+            } else {
+                $title = 'Whoops, looks like something went wrong.';
             }
         }
 
@@ -278,6 +284,14 @@
      */
     public function getStylesheet(FlattenException $exception)
     {
+        if (!$this->debug) {
+            return <<<'EOF'
+                body { background-color: #fff; color: #222; font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; margin: 0; }
+                .container { margin: 30px; max-width: 600px; }
+                h1 { color: #dc3545; font-size: 24px; }
+EOF;
+        }
+
         return <<<'EOF'
             body { background-color: #F9F9F9; color: #222; font: 14px/1.4 Helvetica, Arial, sans-serif; margin: 0; padding-bottom: 45px; }
 
@@ -362,17 +376,17 @@
         }
 
         if (\is_string($fmt)) {
-            $i = strpos($f = $fmt, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: strlen($f);
-            $fmt = array(substr($f, 0, $i)) + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE);
+            $i = strpos($f = $fmt, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: \strlen($f);
+            $fmt = [substr($f, 0, $i)] + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE);
 
             for ($i = 1; isset($fmt[$i]); ++$i) {
                 if (0 === strpos($path, $k = $fmt[$i++])) {
-                    $path = substr_replace($path, $fmt[$i], 0, strlen($k));
+                    $path = substr_replace($path, $fmt[$i], 0, \strlen($k));
                     break;
                 }
             }
 
-            $link = strtr($fmt[0], array('%f' => $path, '%l' => $line));
+            $link = strtr($fmt[0], ['%f' => $path, '%l' => $line]);
         } else {
             $link = $fmt->format($path, $line);
         }
@@ -389,12 +403,12 @@
      */
     private function formatArgs(array $args)
     {
-        $result = array();
+        $result = [];
         foreach ($args as $key => $item) {
             if ('object' === $item[0]) {
                 $formattedValue = sprintf('<em>object</em>(%s)', $this->formatClass($item[1]));
             } elseif ('array' === $item[0]) {
-                $formattedValue = sprintf('<em>array</em>(%s)', is_array($item[1]) ? $this->formatArgs($item[1]) : $item[1]);
+                $formattedValue = sprintf('<em>array</em>(%s)', \is_array($item[1]) ? $this->formatArgs($item[1]) : $item[1]);
             } elseif ('null' === $item[0]) {
                 $formattedValue = '<em>null</em>';
             } elseif ('boolean' === $item[0]) {
@@ -405,7 +419,7 @@
                 $formattedValue = str_replace("\n", '', $this->escapeHtml(var_export($item[1], true)));
             }
 
-            $result[] = is_int($key) ? $formattedValue : sprintf("'%s' => %s", $this->escapeHtml($key), $formattedValue);
+            $result[] = \is_int($key) ? $formattedValue : sprintf("'%s' => %s", $this->escapeHtml($key), $formattedValue);
         }
 
         return implode(', ', $result);