Skip to content

Commit 6fb1f9d

Browse files
committed
ICL: RuntimeException added with support of passing context.
1 parent 3342561 commit 6fb1f9d

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/ExceptionHandler.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,21 @@ public function __construct()
2020

2121
public function report(Exception $e)
2222
{
23-
$this->log->error($e->getMessage(), [
23+
$context = [
2424
'code' => $e->getCode(),
2525
'message' => $e->getMessage(),
2626
'file' => $e->getFile(),
2727
'line' => $e->getLine(),
28-
]);
28+
];
29+
30+
if ($e instanceof RuntimeException) {
31+
$eContext = $e->getContext();
32+
if (!empty($eContext)) {
33+
$context['context'] = $eContext;
34+
}
35+
}
36+
37+
$this->log->error($e->getMessage(), $context);
2938
}
3039

3140
private function registerShutdownFunction()

src/RuntimeException.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Illuminated\Console;
4+
5+
use Exception;
6+
use Symfony\Component\Console\Exception\RuntimeException as SymfonyRuntimeException;
7+
8+
class RuntimeException extends SymfonyRuntimeException
9+
{
10+
private $context;
11+
12+
public function __construct($message = '', array $context = [], $code = 0, Exception $previous = null)
13+
{
14+
$this->context = $context;
15+
16+
parent::__construct($message, $code, $previous);
17+
}
18+
19+
public function getContext()
20+
{
21+
return $this->context;
22+
}
23+
}

0 commit comments

Comments
 (0)