-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogInboundEvent.php
More file actions
59 lines (50 loc) · 1.75 KB
/
LogInboundEvent.php
File metadata and controls
59 lines (50 loc) · 1.75 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/*
* Copyright 2025 Cloud Creativity Limited
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*/
declare(strict_types=1);
namespace CloudCreativity\Modules\Application\InboundEventBus\Middleware;
use Closure;
use CloudCreativity\Modules\Contracts\Application\InboundEventBus\InboundEventMiddleware;
use CloudCreativity\Modules\Contracts\Toolkit\Loggable\ContextFactory;
use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent;
use CloudCreativity\Modules\Toolkit\Loggable\SimpleContextFactory;
use CloudCreativity\Modules\Toolkit\ModuleBasename;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
final readonly class LogInboundEvent implements InboundEventMiddleware
{
/**
* LogInboundEvent constructor.
*
* @param LoggerInterface $log
* @param string $publishLevel
* @param string $publishedLevel
* @param ContextFactory $context
*/
public function __construct(
private LoggerInterface $log,
private string $publishLevel = LogLevel::DEBUG,
private string $publishedLevel = LogLevel::INFO,
private ContextFactory $context = new SimpleContextFactory(),
) {
}
/**
* @inheritDoc
*/
public function __invoke(IntegrationEvent $event, Closure $next): void
{
$name = ModuleBasename::tryFrom($event)?->toString() ?? $event::class;
$this->log->log(
$this->publishLevel,
"Receiving integration event {$name}.",
$context = ['event' => $this->context->make($event)],
);
$next($event);
$this->log->log($this->publishedLevel, "Received integration event {$name}.", $context);
}
}