summaryrefslogtreecommitdiff
path: root/src/Exceptions
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2017-08-29 16:21:25 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2017-08-29 21:52:07 +0200
commitcc01c906ba63b3797bf2b9ef92a6854fe2ddbefb (patch)
treeea819678100f6a50d67f1f8516e82fdef8a9196b /src/Exceptions
parent73175e2b64c85c7a8c528c76452cd82ffa99f925 (diff)
#336: Integration of symfony/http-foundation request
Diffstat (limited to 'src/Exceptions')
-rw-r--r--src/Exceptions/Handler.php56
1 files changed, 50 insertions, 6 deletions
diff --git a/src/Exceptions/Handler.php b/src/Exceptions/Handler.php
index 0532a7d8..6e5b4749 100644
--- a/src/Exceptions/Handler.php
+++ b/src/Exceptions/Handler.php
@@ -34,7 +34,9 @@ class Handler
*/
public function errorHandler($number, $string, $file, $line, $context)
{
- $this->handle('error', $number, $string, $file, $line, $context);
+ $trace = array_reverse(debug_backtrace());
+
+ $this->handle('error', $number, $string, $file, $line, $context, $trace);
}
/**
@@ -59,8 +61,9 @@ class Handler
* @param string $file
* @param int $line
* @param array $context
+ * @param array $trace
*/
- protected function handle($type, $number, $string, $file, $line, $context = [])
+ protected function handle($type, $number, $string, $file, $line, $context = [], $trace = [])
{
error_log(sprintf('%s: Number: %s, String: %s, File: %s:%u, Context: %s',
$type,
@@ -71,13 +74,16 @@ class Handler
json_encode($context)
));
+ $file = $this->stripBasePath($file);
+
if ($this->environment == self::ENV_DEVELOPMENT) {
- echo '<pre style="background-color:#333;color:#ccc;z-index:1000;position:fixed;bottom:1em;padding:1em;width:97%;overflow-y:auto;">';
+ echo '<pre style="background-color:#333;color:#ccc;z-index:1000;position:fixed;bottom:1em;padding:1em;width:97%;max-height: 90%;overflow-y:auto;">';
echo sprintf('%s: (%s)' . PHP_EOL, ucfirst($type), $number);
var_export([
- 'string' => $string,
- 'file' => $file . ':' . $line,
- 'context' => ($this->environment == self::ENV_DEVELOPMENT ? $context : null),
+ 'string' => $string,
+ 'file' => $file . ':' . $line,
+ 'context' => $context,
+ 'stacktrace' => $this->formatStackTrace($trace),
]);
echo '</pre>';
die();
@@ -88,6 +94,44 @@ class Handler
}
/**
+ * @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);
+ }
+
+ /**
* @param string $environment
*/
public function setEnvironment($environment)