-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
667 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
/* | ||
* Copyright 2024 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\EventBus\Middleware; | ||
|
||
use Closure; | ||
use CloudCreativity\Modules\Infrastructure\Log\ObjectContext; | ||
use CloudCreativity\Modules\Toolkit\Messages\IntegrationEventInterface; | ||
use CloudCreativity\Modules\Toolkit\ModuleBasename; | ||
use Psr\Log\LoggerInterface; | ||
use Psr\Log\LogLevel; | ||
|
||
class LogInboundEvent implements IntegrationEventMiddlewareInterface | ||
{ | ||
/** | ||
* LogInboundEvent constructor. | ||
* | ||
* @param LoggerInterface $log | ||
* @param string $publishLevel | ||
* @param string $publishedLevel | ||
*/ | ||
public function __construct( | ||
private readonly LoggerInterface $log, | ||
private readonly string $publishLevel = LogLevel::DEBUG, | ||
private readonly string $publishedLevel = LogLevel::INFO, | ||
) { | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function __invoke(IntegrationEventInterface $event, Closure $next): void | ||
{ | ||
$name = ModuleBasename::tryFrom($event)?->toString() ?? $event::class; | ||
|
||
$this->log->log( | ||
$this->publishLevel, | ||
"Receiving integration event {$name}.", | ||
$context = ObjectContext::from($event)->context(), | ||
); | ||
|
||
$next($event); | ||
|
||
$this->log->log($this->publishedLevel, "Received integration event {$name}.", $context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
/* | ||
* Copyright 2024 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\EventBus\Middleware; | ||
|
||
use Closure; | ||
use CloudCreativity\Modules\Infrastructure\Log\ObjectContext; | ||
use CloudCreativity\Modules\Toolkit\Messages\IntegrationEventInterface; | ||
use CloudCreativity\Modules\Toolkit\ModuleBasename; | ||
use Psr\Log\LoggerInterface; | ||
use Psr\Log\LogLevel; | ||
|
||
class LogOutboundEvent implements IntegrationEventMiddlewareInterface | ||
{ | ||
/** | ||
* LogOutboundEvent constructor. | ||
* | ||
* @param LoggerInterface $log | ||
* @param string $publishLevel | ||
* @param string $publishedLevel | ||
*/ | ||
public function __construct( | ||
private readonly LoggerInterface $log, | ||
private readonly string $publishLevel = LogLevel::DEBUG, | ||
private readonly string $publishedLevel = LogLevel::INFO, | ||
) { | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function __invoke(IntegrationEventInterface $event, Closure $next): void | ||
{ | ||
$name = ModuleBasename::tryFrom($event)?->toString() ?? $event::class; | ||
|
||
$this->log->log( | ||
$this->publishLevel, | ||
"Publishing integration event {$name}.", | ||
$context = ObjectContext::from($event)->context(), | ||
); | ||
|
||
$next($event); | ||
|
||
$this->log->log($this->publishedLevel, "Published integration event {$name}.", $context); | ||
} | ||
} |
Oops, something went wrong.