From d64fc2128ad3e26eaa337ba22a0440dc2479a726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20L=C3=A9cluse?= <laurent.lecluse@unicaen.fr> Date: Thu, 20 Nov 2014 16:27:15 +0000 Subject: [PATCH] =?UTF-8?q?Meilleur=20affichage=20des=20traces=20pou=20d?= =?UTF-8?q?=C3=A9boguer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/UnicaenApp/Util.php | 25 +++++++++++++++++++++++- src/UnicaenApp/View/Helper/Messenger.php | 2 +- view/error/404.phtml | 2 +- view/error/exception.phtml | 4 ++-- view/error/index.phtml | 4 ++-- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/UnicaenApp/Util.php b/src/UnicaenApp/Util.php index f9a0beec..952645f5 100644 --- a/src/UnicaenApp/Util.php +++ b/src/UnicaenApp/Util.php @@ -416,7 +416,30 @@ class Util fclose($handle); return $result; } - + + static public function formatTraceString( $trace ) + { + $result = ''; + $trace = explode( "\n", $trace ); + foreach( $trace as $index => $line ){ + preg_match( '/^#([0-9]+) (.*): (.*)/', $line, $elements ); + if (4 == count($elements)){ + $index = $elements[1]; + $file = $elements[2]; + $code = $elements[3]; + if (class_exists('\Test\Util')){ + $code = \Test\Util::highlight($code, true); + } + $inVendor = false !== strpos($line, '/vendor/'); + $result .= '<div style="'.($inVendor ? 'color:#aaa;' : '' ).'white-space:nowrap">'.$index.' '.$file.'</div>'; + $result .= '<div style="margin-left:5em;margin-bottom:3px">'.$code.'</div>'; + }else{ + $result .= '<div style="white-space:nowrap">'.substr( $line, 1 ).'</div>'; + } + } + return $result; + } + /** * Extrait les feuilles d'un arbre. * diff --git a/src/UnicaenApp/View/Helper/Messenger.php b/src/UnicaenApp/View/Helper/Messenger.php index 28c74fae..0da2a13f 100644 --- a/src/UnicaenApp/View/Helper/Messenger.php +++ b/src/UnicaenApp/View/Helper/Messenger.php @@ -71,7 +71,7 @@ class Messenger extends AbstractHelper return $this->render(); } catch (\Exception $exc) { - var_dump($exc->getMessage(), $exc->getTraceAsString());die; + var_dump($exc->getMessage(), \UnicaenApp\Util::formatTraceString($exc->getTraceAsString()));die; } } diff --git a/view/error/404.phtml b/view/error/404.phtml index aa3465d7..1ea9e7b7 100644 --- a/view/error/404.phtml +++ b/view/error/404.phtml @@ -59,7 +59,7 @@ <h3><?php echo $this->translate('Stack trace') ?>:</h3> <pre> - <?php echo $this->exception->getTraceAsString() ?> + <?php echo \UnicaenApp\Util::formatTraceString($this->exception->getTraceAsString()) ?> </pre> <?php endif ?> diff --git a/view/error/exception.phtml b/view/error/exception.phtml index ce7ffbae..52104480 100644 --- a/view/error/exception.phtml +++ b/view/error/exception.phtml @@ -27,7 +27,7 @@ </dd> <dt><?php echo $this->translate('Stack trace') ?>:</dt> <dd> - <pre class="prettyprint linenums"><?php echo $this->exception->getTraceAsString() ?></pre> + <pre class="prettyprint linenums"><?php echo \UnicaenApp\Util::formatTraceString($this->exception->getTraceAsString()) ?></pre> </dd> </dl> <?php @@ -51,7 +51,7 @@ </dd> <dt><?php echo $this->translate('Stack trace') ?>:</dt> <dd> - <pre class="prettyprint linenums"><?php echo $e->getTraceAsString() ?></pre> + <pre class="prettyprint linenums"><?php echo \UnicaenApp\Util::formatTraceString($e->getTraceAsString()) ?></pre> </dd> </dl> </li> diff --git a/view/error/index.phtml b/view/error/index.phtml index 424ac344..b5364897 100644 --- a/view/error/index.phtml +++ b/view/error/index.phtml @@ -20,7 +20,7 @@ </dd> <dt><?php echo $this->translate('Stack trace') ?>:</dt> <dd> - <pre class="prettyprint linenums"><?php echo $this->exception->getTraceAsString() ?></pre> + <pre class="prettyprint linenums"><?php echo \UnicaenApp\Util::formatTraceString($this->exception->getTraceAsString()) ?></pre> </dd> </dl> <?php @@ -44,7 +44,7 @@ </dd> <dt><?php echo $this->translate('Stack trace') ?>:</dt> <dd> - <pre class="prettyprint linenums"><?php echo $e->getTraceAsString() ?></pre> + <pre class="prettyprint linenums"><?php echo \UnicaenApp\Util::formatTraceString($e->getTraceAsString()) ?></pre> </dd> </dl> </li> -- GitLab