24 lines
794 B
PHP
24 lines
794 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Apoloz\AlfaBank\Http\Middleware;
|
|
|
|
// <SECTION name="module_imports" intent="Import necessary classes for Saloon PendingRequest.">
|
|
// <BELIEF_STATE "These imports are critical for the middleware's operation. `PendingRequest` from Saloon represents the request being prepared for dispatch, allowing modification before sending.">
|
|
use Apoloz\AlfaBank\Utils\Uuid;
|
|
use Saloon\Contracts\RequestMiddleware;
|
|
use Saloon\Http\PendingRequest;
|
|
|
|
class RequestIdMiddleware implements RequestMiddleware
|
|
{
|
|
public function __invoke(PendingRequest $pendingRequest): void
|
|
{
|
|
if (! $pendingRequest->headers()->get('X-Request-ID')) {
|
|
$pendingRequest->headers()->add('X-Request-ID', Uuid::v4());
|
|
}
|
|
}
|
|
// </SECTION>
|
|
}
|
|
// </SECTION>
|