From 25e434bce4986b48bd72729a55aa1096e5a76be3 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Fri, 24 Nov 2017 15:08:43 +0100 Subject: Refactored ExceptionHandler --- src/Exceptions/BasicHandler.php | 119 ---------------------------------------- 1 file changed, 119 deletions(-) delete mode 100644 src/Exceptions/BasicHandler.php (limited to 'src/Exceptions/BasicHandler.php') diff --git a/src/Exceptions/BasicHandler.php b/src/Exceptions/BasicHandler.php deleted file mode 100644 index 2ba960a2..00000000 --- a/src/Exceptions/BasicHandler.php +++ /dev/null @@ -1,119 +0,0 @@ -exceptionHandler($exception); - } - - /** - * @param Throwable $e - */ - public function exceptionHandler($e) - { - $this->handle( - $e->getCode(), - get_class($e) . ': ' . $e->getMessage(), - $e->getFile(), - $e->getLine(), - ['exception' => $e] - ); - } - - /** - * @param int $number - * @param string $string - * @param string $file - * @param int $line - * @param array $context - * @param array $trace - */ - protected function handle($number, $string, $file, $line, $context = [], $trace = []) - { - error_log(sprintf('Exception: Number: %s, String: %s, File: %s:%u, Context: %s', - $number, - $string, - $file, - $line, - json_encode($context) - )); - - $file = $this->stripBasePath($file); - - if ($this->environment == self::ENV_DEVELOPMENT) { - echo '
';
-            echo sprintf('%s: (%s)' . PHP_EOL, ucfirst($type), $number);
-            var_export([
-                'string'     => $string,
-                'file'       => $file . ':' . $line,
-                'context'    => $context,
-                'stacktrace' => $this->formatStackTrace($trace),
-            ]);
-            echo '
'; - die(); - } - - echo 'An unexpected error occurred, a team of untrained monkeys has been dispatched to deal with it.'; - die(); - } - - /** - * @param array $stackTrace - * @return array - */ - protected function formatStackTrace($stackTrace) - { - $return = []; - - foreach ($stackTrace as $trace) { - $path = ''; - $line = ''; - - if (isset($trace['file']) && isset($trace['line'])) { - $path = $this->stripBasePath($trace['file']); - $line = $trace['line']; - } - - $functionName = $trace['function']; - - $return[] = [ - 'file' => $path . ':' . $line, - $functionName => $trace['args'], - ]; - } - - return $return; - } - - /** - * @param string $path - * @return string - */ - protected function stripBasePath($path) - { - $basePath = realpath(__DIR__ . '/../..') . '/'; - return str_replace($basePath, '', $path); - } -} -- cgit v1.2.3-54-g00ecf