From 9052efc499c1d4739dddb84f19718aa9d33c8cf1 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Fri, 12 Sep 2014 13:09:09 +0200 Subject: [PATCH] [Intl] Added exception handler to command line scripts --- .../Component/Intl/Resources/bin/common.php | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Intl/Resources/bin/common.php b/src/Symfony/Component/Intl/Resources/bin/common.php index eb7643dfbd..1e25265d57 100644 --- a/src/Symfony/Component/Intl/Resources/bin/common.php +++ b/src/Symfony/Component/Intl/Resources/bin/common.php @@ -11,11 +11,11 @@ define('LINE_WIDTH', 75); -define('LINE', str_repeat('-', LINE_WIDTH) . "\n"); +define('LINE', str_repeat('-', LINE_WIDTH)."\n"); function bailout($message) { - echo wordwrap($message, LINE_WIDTH) . " Aborting.\n"; + echo wordwrap($message, LINE_WIDTH)." Aborting.\n"; exit(1); } @@ -31,7 +31,7 @@ function centered($text) { $padding = (int) ((LINE_WIDTH - strlen($text))/2); - return str_repeat(' ', $padding) . $text; + return str_repeat(' ', $padding).$text; } function cd($dir) @@ -47,7 +47,7 @@ function run($command) if (0 !== $status) { $output = implode("\n", $output); - echo "Error while running:\n " . getcwd() . '$ ' . $command . "\nOutput:\n" . LINE . "$output\n" . LINE; + echo "Error while running:\n ".getcwd().'$ '.$command."\nOutput:\n".LINE."$output\n".LINE; bailout("\"$command\" failed."); } @@ -55,10 +55,10 @@ function run($command) function get_icu_version_from_genrb($genrb) { - exec($genrb . ' --version 2>&1', $output, $status); + exec($genrb.' --version 2>&1', $output, $status); if (0 !== $status) { - bailout($genrb . ' failed.'); + bailout($genrb.' failed.'); } if (!preg_match('/ICU version ([\d\.]+)/', implode('', $output), $matches)) { @@ -67,3 +67,27 @@ function get_icu_version_from_genrb($genrb) return $matches[1]; } + +set_exception_handler(function (\Exception $exception) { + echo "\n"; + + $cause = $exception; + $root = true; + + while (null !== $cause) { + if (!$root) { + echo "Caused by\n"; + } + + echo get_class($cause).": ".$cause->getMessage()."\n"; + echo "\n"; + echo $cause->getFile().":".$cause->getLine()."\n"; + foreach ($cause->getTrace() as $trace) { + echo $trace['file'].":".$trace['line']."\n"; + } + echo "\n"; + + $cause = $cause->getPrevious(); + $root = false; + } +});