Enable Discovery debug logging for production troubleshooting
- Add DISCOVERY_LOG_LEVEL=debug - Add DISCOVERY_SHOW_PROGRESS=true - Temporary changes for debugging InitializerProcessor fixes on production
This commit is contained in:
@@ -4,44 +4,43 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\Core;
|
||||
|
||||
use App\Framework\Cache\Cache;
|
||||
use App\Framework\Config\Configuration;
|
||||
use App\Framework\Config\TypedConfiguration;
|
||||
use App\Framework\Core\Events\AfterEmitResponse;
|
||||
use App\Framework\Core\Events\AfterHandleRequest;
|
||||
use App\Framework\Core\Events\ApplicationBooted;
|
||||
use App\Framework\Core\Events\BeforeEmitResponse;
|
||||
use App\Framework\Core\Events\BeforeHandleRequest;
|
||||
use App\Framework\Core\Events\EventCompilerPass;
|
||||
use App\Framework\Core\Events\EventDispatcher;
|
||||
use App\Framework\Core\Events\OnEvent;
|
||||
use App\Framework\DI\DefaultContainer;
|
||||
use App\Framework\Core\Events\EventDispatcherInterface;
|
||||
use App\Framework\DI\Container;
|
||||
use App\Framework\DI\Initializer;
|
||||
use App\Framework\Http\MiddlewareManager;
|
||||
use App\Framework\Http\MiddlewareManagerInterface;
|
||||
use App\Framework\Http\Request;
|
||||
use App\Framework\Http\Response;
|
||||
use App\Framework\Http\ResponseEmitter;
|
||||
use App\Framework\Performance\Contracts\PerformanceCollectorInterface;
|
||||
use App\Framework\Performance\PerformanceCategory;
|
||||
use App\Framework\Router\HttpRouter;
|
||||
use DateTimeImmutable;
|
||||
|
||||
final readonly class Application
|
||||
final readonly class Application implements ApplicationInterface
|
||||
{
|
||||
private MiddlewareManager $middlewareManager;
|
||||
private AttributeDiscoveryService $discoveryService;
|
||||
private EventDispatcher $eventDispatcher;
|
||||
private MiddlewareManagerInterface $middlewareManager;
|
||||
|
||||
private EventDispatcherInterface $eventDispatcher;
|
||||
|
||||
private PerformanceCollectorInterface $performanceCollector;
|
||||
|
||||
public function __construct(
|
||||
private Container $container,
|
||||
private PathProvider $pathProvider,
|
||||
private ResponseEmitter $responseEmitter,
|
||||
private Configuration $config
|
||||
private TypedConfiguration $config,
|
||||
?MiddlewareManagerInterface $middlewareManager = null,
|
||||
?EventDispatcherInterface $eventDispatcher = null,
|
||||
?PerformanceCollectorInterface $performanceCollector = null,
|
||||
) {
|
||||
// Middleware-Manager initialisieren
|
||||
$this->middlewareManager = $this->container->get(MiddlewareManager::class);
|
||||
|
||||
$this->eventDispatcher = $container->get(EventDispatcher::class);
|
||||
|
||||
// Discovery-Service initialisieren
|
||||
#$this->discoveryService = new AttributeDiscoveryService($container, $pathProvider, $config);
|
||||
// Dependencies optional injizieren oder aus Container holen
|
||||
$this->middlewareManager = $middlewareManager ?? $this->container->get(MiddlewareManagerInterface::class);
|
||||
$this->eventDispatcher = $eventDispatcher ?? $this->container->get(EventDispatcherInterface::class);
|
||||
$this->performanceCollector = $performanceCollector ?? $this->container->get(PerformanceCollectorInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,55 +48,70 @@ final readonly class Application
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// ApplicationBooted-Event dispatchen
|
||||
$environment = $this->config->get('environment', 'dev');
|
||||
$version = $this->config->get('app.version', 'dev');
|
||||
$this->boot();
|
||||
$response = $this->handleRequest($this->container->get(Request::class));
|
||||
$this->emitResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap der Anwendung
|
||||
*/
|
||||
private function boot(): void
|
||||
{
|
||||
// ApplicationBooted-Event dispatchen
|
||||
$environment = $this->config->app->environment;
|
||||
$version = $this->config->app->version;
|
||||
|
||||
$bootEvent = new ApplicationBooted(
|
||||
new DateTimeImmutable(),
|
||||
$environment,
|
||||
$version
|
||||
bootTime: new DateTimeImmutable(),
|
||||
environment: $environment,
|
||||
version: $version
|
||||
);
|
||||
|
||||
$this->event($bootEvent);
|
||||
|
||||
// Attribute verarbeiten und Komponenten einrichten
|
||||
#$this->setupApplicationComponents();
|
||||
|
||||
// Sicherstellen, dass ein Router registriert wurde
|
||||
if (!$this->container->has(HttpRouter::class)) {
|
||||
if (! $this->container->has(HttpRouter::class)) {
|
||||
throw new \RuntimeException('Kritischer Fehler: Router wurde nicht initialisiert');
|
||||
}
|
||||
}
|
||||
|
||||
$this->event(new BeforeHandleRequest);
|
||||
/**
|
||||
* Verarbeitet den HTTP-Request
|
||||
*/
|
||||
private function handleRequest(Request $request): Response
|
||||
{
|
||||
$this->event(new BeforeHandleRequest());
|
||||
|
||||
$response = $this->performanceCollector->measure(
|
||||
'handle_request',
|
||||
PerformanceCategory::SYSTEM,
|
||||
function () use ($request) {
|
||||
return $this->middlewareManager->chain->handle($request);
|
||||
}
|
||||
);
|
||||
|
||||
$this->event(new AfterHandleRequest);
|
||||
#$response = $this->middlewareManager->chain->handle($request);
|
||||
|
||||
$request = $this->container->get(Request::class);
|
||||
$this->event(new AfterHandleRequest());
|
||||
|
||||
$response = $this->middlewareManager->chain->handle($request);
|
||||
return $response;
|
||||
}
|
||||
|
||||
$this->event(new BeforeEmitResponse);
|
||||
/**
|
||||
* Gibt die HTTP-Response aus
|
||||
*/
|
||||
private function emitResponse(Response $response): void
|
||||
{
|
||||
$this->event(new BeforeEmitResponse());
|
||||
|
||||
// Response ausgeben
|
||||
$this->responseEmitter->emit($response);
|
||||
|
||||
$this->event(new AfterEmitResponse);
|
||||
$this->event(new AfterEmitResponse());
|
||||
}
|
||||
|
||||
private function event(object $event): void
|
||||
{
|
||||
$this->eventDispatcher->dispatch($event);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gibt einen Konfigurationswert zurück
|
||||
*/
|
||||
public function config(string $key, mixed $default = null): mixed
|
||||
{
|
||||
return $this->config->get($key, $default);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user