-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExceptionCodeProcessor.php
More file actions
40 lines (35 loc) · 1.16 KB
/
ExceptionCodeProcessor.php
File metadata and controls
40 lines (35 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php declare(strict_types=1);
namespace KoderHut\OnelogBundle\Middleware;
use KoderHut\OnelogBundle\ContextualInterface;
/**
* Class ExceptionCodeProcessor
*
* @author Joao Jacome <969041+joaojacome@users.noreply.github.com>
*/
class ExceptionCodeProcessor implements MiddlewareInterface
{
/**
* @param string $level
* @param mixed $message
* @param array $context
* @param bool|false $nesting
*
* @return array
*/
public function process($level, $message, $context, $nesting=false): array
{
if ($message instanceof \Throwable && $message->getPrevious() && $message->getPrevious() instanceof \Throwable) {
$nesting = true;
[$previousMessage, $context] = $this->process($level, $message->getPrevious(), $context, true);
}
if ($message instanceof \Throwable) {
$context = array_merge($context, [
'code' => $message->getCode(),
]);
if ($nesting) {
$context['codes'] = array_merge([$message->getCode()], $context['codes'] ?? []);
}
}
return [$message, $context];
}
}