{
"event": "PreToolUse",
"tool_name": "Write",
"tool_input": {
"file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Framework\/Middleware\/CorrelationMiddleware.php",
"content": "<?php\n\nnamespace Framework\\Middleware;\n\n\/**\n * Middleware to ensure every request has a correlation ID.\n *\n * The correlation ID is used to trace all log entries for a single request.\n * It can be passed in via X-Correlation-ID header or generated automatically.\n *\/\nfinal class CorrelationMiddleware\n{\n \/**\n * Handle the request and set correlation ID.\n *\n * @param callable $next The next handler in the chain\n *\/\n public function handle(callable $next): void\n {\n $correlationId = $this->getOrCreateCorrelationId();\n\n \/\/ Make globally available\n $_SERVER['CORRELATION_ID'] = $correlationId;\n\n \/\/ Set response header for tracing\n if (!headers_sent()) {\n header(\"X-Correlation-ID: {$correlationId}\");\n }\n\n $next();\n }\n\n \/**\n * Get existing correlation ID from header or generate new one.\n *\/\n private function getOrCreateCorrelationId(): string\n {\n \/\/ Check for existing correlation ID in headers\n if (isset($_SERVER['HTTP_X_CORRELATION_ID']) && $_SERVER['HTTP_X_CORRELATION_ID'] !== '') {\n return $_SERVER['HTTP_X_CORRELATION_ID'];\n }\n\n \/\/ Generate new correlation ID\n return bin2hex(random_bytes(8));\n }\n\n \/**\n * Get the current correlation ID.\n *\/\n public static function getCorrelationId(): string\n {\n return $_SERVER['CORRELATION_ID'] ?? bin2hex(random_bytes(8));\n }\n}\n"
}
}
{
"tool_response": {
"type": "create",
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Framework\/Middleware\/CorrelationMiddleware.php",
"content": "<?php\n\nnamespace Framework\\Middleware;\n\n\/**\n * Middleware to ensure every request has a correlation ID.\n *\n * The correlation ID is used to trace all log entries for a single request.\n * It can be passed in via X-Correlation-ID header or generated automatically.\n *\/\nfinal class CorrelationMiddleware\n{\n \/**\n * Handle the request and set correlation ID.\n *\n * @param callable $next The next handler in the chain\n *\/\n public function handle(callable $next): void\n {\n $correlationId = $this->getOrCreateCorrelationId();\n\n \/\/ Make globally available\n $_SERVER['CORRELATION_ID'] = $correlationId;\n\n \/\/ Set response header for tracing\n if (!headers_sent()) {\n header(\"X-Correlation-ID: {$correlationId}\");\n }\n\n $next();\n }\n\n \/**\n * Get existing correlation ID from header or generate new one.\n *\/\n private function getOrCreateCorrelationId(): string\n {\n \/\/ Check for existing correlation ID in headers\n if (isset($_SERVER['HTTP_X_CORRELATION_ID']) && $_SERVER['HTTP_X_CORRELATION_ID'] !== '') {\n return $_SERVER['HTTP_X_CORRELATION_ID'];\n }\n\n \/\/ Generate new correlation ID\n return bin2hex(random_bytes(8));\n }\n\n \/**\n * Get the current correlation ID.\n *\/\n public static function getCorrelationId(): string\n {\n return $_SERVER['CORRELATION_ID'] ?? bin2hex(random_bytes(8));\n }\n}\n",
"structuredPatch": [],
"originalFile": null
}
}