CorrelationMiddleware.php
- Pfad:
src/Framework/Middleware/CorrelationMiddleware.php - Namespace: Framework\Middleware
- Zeilen: 53 | Größe: 1,324 Bytes
- Geändert: 2025-12-23 08:09:11 | Gescannt: 2025-12-31 10:22:15
Code Hygiene Score: 100
- Dependencies: 100 (25%)
- LOC: 100 (20%)
- Methods: 100 (20%)
- Secrets: 100 (15%)
- Classes: 100 (10%)
- Magic Numbers: 100 (10%)
Keine Issues gefunden.
Klassen 1
-
CorrelationMiddlewareclass Zeile 9
Funktionen 3
-
handle()public Zeile 16 -
getOrCreateCorrelationId()Zeile 34 -
getCorrelationId()Zeile 48
Verwendet von 1
- App.php use
Versionen 1
-
v1
2025-12-23 08:09 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
Code
<?php
declare(strict_types=1);
namespace Framework\Middleware;
// @responsibility: Middleware für Request-Correlation-ID (Tracing)
final class CorrelationMiddleware
{
/**
* Handle the request and set correlation ID.
*
* @param callable $next The next handler in the chain
*/
public function handle(callable $next): void
{
$correlationId = $this->getOrCreateCorrelationId();
// Make globally available
$_SERVER['CORRELATION_ID'] = $correlationId;
// Set response header for tracing
if (!headers_sent()) {
header("X-Correlation-ID: {$correlationId}");
}
$next();
}
/**
* Get existing correlation ID from header or generate new one.
*/
private function getOrCreateCorrelationId(): string
{
// Check for existing correlation ID in headers
if (isset($_SERVER['HTTP_X_CORRELATION_ID']) && $_SERVER['HTTP_X_CORRELATION_ID'] !== '') {
return $_SERVER['HTTP_X_CORRELATION_ID'];
}
// Generate new correlation ID
return bin2hex(random_bytes(8));
}
/**
* Get the current correlation ID.
*/
public static function getCorrelationId(): string
{
return $_SERVER['CORRELATION_ID'] ?? bin2hex(random_bytes(8));
}
}