refactor: Framework code cleanup and improvements
- DI dependency graph improvements - Database connection updates - HTTP middleware chain optimizations - Routing middleware cleanup
This commit is contained in:
@@ -48,11 +48,6 @@ final class InitializerDependencyGraph
|
|||||||
dependencies: $dependencies
|
dependencies: $dependencies
|
||||||
);
|
);
|
||||||
|
|
||||||
// Debug RouterSetup specifically
|
|
||||||
if (str_contains($className->toString(), 'RouterSetup')) {
|
|
||||||
error_log("InitializerDependencyGraph: Adding RouterSetup node - " . $className->toString() . " -> " . $returnType);
|
|
||||||
error_log("InitializerDependencyGraph: RouterSetup dependencies: " . implode(', ', $dependencies));
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->nodes[$returnType] = $node;
|
$this->nodes[$returnType] = $node;
|
||||||
$this->adjacencyList[$returnType] = $dependencies;
|
$this->adjacencyList[$returnType] = $dependencies;
|
||||||
|
|||||||
@@ -16,13 +16,10 @@ use App\Framework\Database\ValueObjects\SqlState;
|
|||||||
|
|
||||||
final class PdoConnection implements ConnectionInterface
|
final class PdoConnection implements ConnectionInterface
|
||||||
{
|
{
|
||||||
private \PDO $pdo;
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
\PDO $pdo,
|
private \PDO $pdo,
|
||||||
private ?SqlStateErrorMapper $errorMapper = null
|
private ?SqlStateErrorMapper $errorMapper = null
|
||||||
) {
|
) {
|
||||||
$this->pdo = $pdo;
|
|
||||||
$this->errorMapper ??= new SqlStateErrorMapper();
|
$this->errorMapper ??= new SqlStateErrorMapper();
|
||||||
|
|
||||||
# SOllte bereits aus den Options kommen!
|
# SOllte bereits aus den Options kommen!
|
||||||
@@ -38,7 +35,7 @@ final class PdoConnection implements ConnectionInterface
|
|||||||
|
|
||||||
return $statement->rowCount();
|
return $statement->rowCount();
|
||||||
} catch (\PDOException $e) {
|
} catch (\PDOException $e) {
|
||||||
throw $this->handlePdoException($e, $query->sql);
|
$this->handlePdoException($e, $query->sql);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +47,7 @@ final class PdoConnection implements ConnectionInterface
|
|||||||
|
|
||||||
return new PdoResult($statement);
|
return new PdoResult($statement);
|
||||||
} catch (\PDOException $e) {
|
} catch (\PDOException $e) {
|
||||||
throw $this->handlePdoException($e, $query->sql);
|
$this->handlePdoException($e, $query->sql);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ final readonly class DatabaseErrorStorage implements ErrorStorageInterface
|
|||||||
public function getPatternById(string $patternId): ?ErrorPattern
|
public function getPatternById(string $patternId): ?ErrorPattern
|
||||||
{
|
{
|
||||||
$sql = "SELECT * FROM error_patterns WHERE id = ?";
|
$sql = "SELECT * FROM error_patterns WHERE id = ?";
|
||||||
$result = $this->connection->query($sql, [$patternId]);
|
$result = $this->getConnection()->query($sql, [$patternId]);
|
||||||
|
|
||||||
if (empty($result)) {
|
if (empty($result)) {
|
||||||
return null;
|
return null;
|
||||||
@@ -183,7 +183,7 @@ final readonly class DatabaseErrorStorage implements ErrorStorageInterface
|
|||||||
LIMIT ?
|
LIMIT ?
|
||||||
";
|
";
|
||||||
|
|
||||||
$results = $this->connection->query($sql, [$service, $limit]);
|
$results = $this->getConnection()->query($sql, [$service, $limit]);
|
||||||
|
|
||||||
return array_map([$this, 'hydratePattern'], $results);
|
return array_map([$this, 'hydratePattern'], $results);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,21 +30,20 @@ final readonly class HttpMiddlewareChain implements HttpMiddlewareChainInterface
|
|||||||
|
|
||||||
$this->stateManager = new MiddlewareStateManager()->forRequest($request);
|
$this->stateManager = new MiddlewareStateManager()->forRequest($request);
|
||||||
|
|
||||||
// Start der Middleware-Chain loggen
|
|
||||||
error_log("🚀 MIDDLEWARE CHAIN START - URI: {$request->path}, Method: {$request->method->value}, Middleware-Count: " . count($this->middlewares));
|
|
||||||
|
|
||||||
// Middleware-Stack durchlaufen
|
// Middleware-Stack durchlaufen
|
||||||
$resultContext = $this->doProcessMiddlewareStack($context, 0);
|
$resultContext = $this->doProcessMiddlewareStack($context, 0);
|
||||||
|
|
||||||
// Ende der Middleware-Chain loggen
|
// Ende der Middleware-Chain
|
||||||
if ($resultContext->hasResponse()) {
|
if ($resultContext->hasResponse()) {
|
||||||
error_log("✅ MIDDLEWARE CHAIN COMPLETE - Final Response Status: {$resultContext->response?->status->value}");
|
|
||||||
|
|
||||||
return $resultContext->response;
|
return $resultContext->response;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wenn keine Response vorhanden ist, ist das ein Fehler in der Middleware-Konfiguration
|
// Wenn keine Response vorhanden ist, ist das ein Fehler in der Middleware-Konfiguration
|
||||||
error_log("❌ MIDDLEWARE CHAIN FAILED - No response created after processing all middlewares");
|
$this->logger->error('No response created after processing all middlewares', LogContext::withData([
|
||||||
|
'uri' => $request->path,
|
||||||
|
'method' => $request->method->value,
|
||||||
|
'middleware_count' => count($this->middlewares),
|
||||||
|
]));
|
||||||
|
|
||||||
throw new \RuntimeException(sprintf(
|
throw new \RuntimeException(sprintf(
|
||||||
'Keine Response nach Middleware-Chain erstellt. Stellen Sie sicher, dass eine DefaultResponseMiddleware konfiguriert ist. URI: %s, Method: %s, Middleware-Count: %d',
|
'Keine Response nach Middleware-Chain erstellt. Stellen Sie sicher, dass eine DefaultResponseMiddleware konfiguriert ist. URI: %s, Method: %s, Middleware-Count: %d',
|
||||||
@@ -66,12 +65,6 @@ final readonly class HttpMiddlewareChain implements HttpMiddlewareChainInterface
|
|||||||
$middleware = $this->middlewares[$index];
|
$middleware = $this->middlewares[$index];
|
||||||
$middlewareName = $this->getMiddlewareName($middleware);
|
$middlewareName = $this->getMiddlewareName($middleware);
|
||||||
|
|
||||||
// Start der Middleware loggen
|
|
||||||
error_log("🔄 MIDDLEWARE #{$index} START: {$middlewareName}");
|
|
||||||
|
|
||||||
// Status VOR der Middleware loggen
|
|
||||||
$this->logDebug("VOR Middleware #{$index} ({$middlewareName})", $context, $index);
|
|
||||||
|
|
||||||
// Next-Handler erstellen, der zur nächsten Middleware weiterleitet
|
// Next-Handler erstellen, der zur nächsten Middleware weiterleitet
|
||||||
$next = new readonly class ($this, $index, $middlewareName) implements Next {
|
$next = new readonly class ($this, $index, $middlewareName) implements Next {
|
||||||
public function __construct(
|
public function __construct(
|
||||||
@@ -157,38 +150,13 @@ final readonly class HttpMiddlewareChain implements HttpMiddlewareChainInterface
|
|||||||
?int $responseBeforeStatus,
|
?int $responseBeforeStatus,
|
||||||
?int $responseAfterStatus
|
?int $responseAfterStatus
|
||||||
): void {
|
): void {
|
||||||
// Response wurde erstellt
|
// Response wurde verloren - das ist ein Problem
|
||||||
if (! $hadResponseBefore && $hasResponseAfter) {
|
|
||||||
error_log("✅ RESPONSE CREATED by Middleware #{$index} ({$middlewareName}) - Status: {$responseAfterStatus}");
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Response wurde verloren
|
|
||||||
if ($hadResponseBefore && ! $hasResponseAfter) {
|
if ($hadResponseBefore && ! $hasResponseAfter) {
|
||||||
error_log("❌ RESPONSE LOST by Middleware #{$index} ({$middlewareName}) - Previous Status: {$responseBeforeStatus}");
|
$this->logger->warning('Response lost by middleware', LogContext::withData([
|
||||||
|
'middleware' => $middlewareName,
|
||||||
return;
|
'middleware_index' => $index,
|
||||||
}
|
'previous_status' => $responseBeforeStatus,
|
||||||
|
]));
|
||||||
// Response-Status wurde geändert
|
|
||||||
if ($hadResponseBefore && $hasResponseAfter && $responseBeforeStatus !== $responseAfterStatus) {
|
|
||||||
error_log("🔄 RESPONSE MODIFIED by Middleware #{$index} ({$middlewareName}) - Status: {$responseBeforeStatus} → {$responseAfterStatus}");
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Response blieb unverändert (normal)
|
|
||||||
if ($hadResponseBefore && $hasResponseAfter && $responseBeforeStatus === $responseAfterStatus) {
|
|
||||||
error_log("➡️ RESPONSE PASSED THROUGH Middleware #{$index} ({$middlewareName}) - Status: {$responseAfterStatus}");
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Keine Response vor und nach der Middleware (normal für frühe Middlewares)
|
|
||||||
// @phpstan-ignore booleanNot.alwaysTrue
|
|
||||||
if (! $hadResponseBefore && ! $hasResponseAfter) {
|
|
||||||
error_log("⚪ NO RESPONSE before/after Middleware #{$index} ({$middlewareName})");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -149,11 +149,6 @@ final readonly class RoutingMiddleware implements HttpMiddleware
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
error_log("RoutingMiddleware: Setting CONTROLLER_RESULT of type: " . get_class($result));
|
|
||||||
if (method_exists($result, 'template')) {
|
|
||||||
error_log("RoutingMiddleware: Result template: " . $result->template);
|
|
||||||
}
|
|
||||||
|
|
||||||
$stateManager->set(StateKey::CONTROLLER_RESULT, $result);
|
$stateManager->set(StateKey::CONTROLLER_RESULT, $result);
|
||||||
|
|
||||||
// Nächste Middleware aufrufen
|
// Nächste Middleware aufrufen
|
||||||
|
|||||||
Reference in New Issue
Block a user