This commit is contained in:
2026-01-18 23:53:31 +03:00
parent 17eec3ebc0
commit 6a7325f0fd
334 changed files with 1074 additions and 680 deletions

View File

@@ -1,24 +1,16 @@
<?php
/*
// MODULE_CONTRACT: Provides a Saloon middleware for logging API requests and responses, with sensitive data masking.
// RESPONSIBILITY: To intercept and log outgoing API requests and incoming API responses, providing visibility into the communication flow for debugging and monitoring purposes, while also sanitizing sensitive information from logs to maintain security and compliance.
// INPUTS: Psr\Log\LoggerInterface for logging; Saloon `Request` and `Response` objects.
// OUTPUTS: Logs detailed request and response information (with masked sensitive data) to the configured logger.
// LINKS: Core/AlfaBankConnector.php, Sbp/SbpConnector.php, README.md#logging
*/
declare(strict_types=1);
namespace Apoloz\AlfaBank\Http\Middleware;
// <SECTION name="module_imports" intent="Import necessary classes for logging and Saloon HTTP components.">
// <BELIEF_STATE "These imports are fundamental for the logging middleware. `LoggerInterface` from PSR-3 defines the contract for logging, allowing flexibility in the choice of logging implementation. `Request` and `Response` from Saloon are the HTTP objects that this middleware will observe and log, providing insights into the API communication lifecycle.">
use Psr\Log\LoggerInterface;
use Saloon\Contracts\RequestMiddleware;
use Saloon\Contracts\ResponseMiddleware;
use Saloon\Http\PendingRequest;
use Saloon\Http\Response;
// </SECTION>
// <SECTION name="class_definition" intent="Define the API request and response logging middleware.">
// <BELIEF_STATE "The `LoggingMiddleware` plays a crucial role in the observability of the SDK. By implementing `onRequest` and `onResponse` methods, it captures detailed information about HTTP interactions, including headers and body. Crucially, it incorporates sensitive data masking to prevent credentials and personal information from being exposed in logs, balancing transparency with security and compliance requirements.">
class LoggingMiddleware
class LoggingMiddleware implements RequestMiddleware, ResponseMiddleware
{
// <SECTION name="constructor_definition" intent="Initialize the middleware with a logger instance.">
// <BELIEF_STATE "The constructor injects a `LoggerInterface` instance, making the logging functionality easily testable and configurable. This adheres to dependency inversion principles, allowing the middleware to log messages without being tightly coupled to a specific logging implementation.">