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:
@@ -1,16 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\EventBus;
|
||||
|
||||
use App\Framework\DI\DefaultContainer;
|
||||
use App\Framework\DI\Container;
|
||||
use App\Framework\Logging\Logger;
|
||||
|
||||
final readonly class DefaultEventBus implements EventBus
|
||||
{
|
||||
public function __construct(
|
||||
private array $eventHandlers,
|
||||
private DefaultContainer $container
|
||||
) {}
|
||||
private Container $container,
|
||||
private Logger $logger
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatcht ein Event an alle registrierten Handler
|
||||
@@ -18,13 +22,14 @@ final readonly class DefaultEventBus implements EventBus
|
||||
* @param object $event Das zu dispatchende Event
|
||||
* @return void
|
||||
*/
|
||||
public function dispatch(object $event): void {
|
||||
public function dispatch(object $event): void
|
||||
{
|
||||
$eventClass = get_class($event);
|
||||
|
||||
error_log('Dispatching Event: ' . $eventClass);
|
||||
// Debug logging removed for production - only log errors
|
||||
|
||||
// Prüfe, ob Handler für diesen Event-Typ registriert sind
|
||||
if (empty($this->eventHandlers) || !isset($this->eventHandlers[$eventClass])) {
|
||||
if (empty($this->eventHandlers) || ! isset($this->eventHandlers[$eventClass])) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -44,8 +49,12 @@ final readonly class DefaultEventBus implements EventBus
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
// Fehler in Event-Handlern sollten die Anwendung nicht abstürzen lassen
|
||||
// In einer echten Anwendung würde hier ein Logger verwendet
|
||||
error_log('Fehler bei der Ausführung des Event-Handlers: ' . $e->getMessage());
|
||||
$this->logger->error("EventBus: ❌ Event handler failed", [
|
||||
'event_class' => $eventClass,
|
||||
'handler_class' => $handler['class'],
|
||||
'handler_method' => $handler['method'],
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\EventBus;
|
||||
|
||||
interface EventBus
|
||||
|
||||
@@ -1,28 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\EventBus;
|
||||
|
||||
use App\Framework\DI\Container;
|
||||
use App\Framework\DI\Initializer;
|
||||
use App\Framework\Discovery\Results\DiscoveryResults;
|
||||
use App\Framework\Discovery\Results\DiscoveryRegistry;
|
||||
use App\Framework\Logging\Logger;
|
||||
|
||||
final readonly class EventBusInitializer
|
||||
{
|
||||
public function __construct(
|
||||
private Container $container,
|
||||
private DiscoveryResults $results
|
||||
){}
|
||||
private DiscoveryRegistry $results
|
||||
) {
|
||||
}
|
||||
|
||||
#[Initializer]
|
||||
public function __invoke(): EventBus
|
||||
public function __invoke(Logger $logger): EventBus
|
||||
{
|
||||
$handlers = $this->results->get(EventHandler::class);
|
||||
$handlerResults = $this->results->attributes->get(EventHandler::class);
|
||||
|
||||
$eventHandlers = [];
|
||||
foreach ($handlers as $handler) {
|
||||
$eventHandlers[$handler['event_class']] = $handler;
|
||||
foreach ($handlerResults as $discoveredAttribute) {
|
||||
if ($discoveredAttribute->additionalData) {
|
||||
$handler = $discoveredAttribute->additionalData;
|
||||
$eventHandlers[$handler['event_class']] = $handler;
|
||||
}
|
||||
}
|
||||
|
||||
return new DefaultEventBus($eventHandlers, $this->container);
|
||||
return new DefaultEventBus($eventHandlers, $this->container, $logger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\EventBus;
|
||||
@@ -20,5 +21,6 @@ final readonly class EventHandler
|
||||
public function __construct(
|
||||
public ?int $priority = null,
|
||||
public bool $stopPropagation = false
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\EventBus;
|
||||
@@ -41,12 +42,12 @@ final readonly class EventHandlerCompiler implements AttributeCompiler
|
||||
$stopPropagation = $handler['attribute_data']['stopPropagation'] ?? false;
|
||||
|
||||
// Prüfe, ob alle erforderlichen Daten vorhanden sind
|
||||
if (!$className || !$methodName || !$eventClass) {
|
||||
if (! $className || ! $methodName || ! $eventClass) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Füge den Handler zur Liste der Handler für diesen Event-Typ hinzu
|
||||
if (!isset($compiledHandlers[$eventClass])) {
|
||||
if (! isset($compiledHandlers[$eventClass])) {
|
||||
$compiledHandlers[$eventClass] = [];
|
||||
}
|
||||
|
||||
@@ -54,7 +55,7 @@ final readonly class EventHandlerCompiler implements AttributeCompiler
|
||||
'class' => $className,
|
||||
'method' => $methodName,
|
||||
'priority' => $priority,
|
||||
'stopPropagation' => $stopPropagation
|
||||
'stopPropagation' => $stopPropagation,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\EventBus;
|
||||
|
||||
use App\Framework\Core\AttributeMapper;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
use App\Framework\Reflection\WrappedReflectionClass;
|
||||
use App\Framework\Reflection\WrappedReflectionMethod;
|
||||
|
||||
/**
|
||||
* Mapper für das EventHandler-Attribut
|
||||
@@ -22,14 +23,10 @@ final class EventHandlerMapper implements AttributeMapper
|
||||
|
||||
/**
|
||||
* Implementiert die map-Methode aus dem AttributeMapper-Interface
|
||||
*
|
||||
* @param object $reflectionTarget Das Reflektionsobjekt (ReflectionClass|ReflectionMethod)
|
||||
* @param object $attributeInstance Die Attributinstanz
|
||||
* @return array|null Die Attributdaten oder null, wenn nicht verarbeitet werden kann
|
||||
*/
|
||||
public function map(object $reflectionTarget, object $attributeInstance): ?array
|
||||
public function map(WrappedReflectionClass|WrappedReflectionMethod $reflectionTarget, object $attributeInstance): ?array
|
||||
{
|
||||
if (!($reflectionTarget instanceof ReflectionMethod)) {
|
||||
if (! ($reflectionTarget instanceof WrappedReflectionMethod)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -41,19 +38,19 @@ final class EventHandlerMapper implements AttributeMapper
|
||||
}
|
||||
|
||||
$eventType = $parameters[0]->getType();
|
||||
if (!$eventType || $eventType->isBuiltin()) {
|
||||
if (! $eventType || $eventType->isBuiltin()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$eventClassName = $eventType->getName();
|
||||
|
||||
return [
|
||||
'class' => $reflectionTarget->getDeclaringClass()->getName(),
|
||||
'class' => $reflectionTarget->getDeclaringClass()->getFullyQualified(),
|
||||
'method' => $reflectionTarget->getName(),
|
||||
'event_class' => $eventClassName,
|
||||
'attribute_data' => [
|
||||
'priority' => $attributeInstance->priority ?? 0,
|
||||
'stopPropagation' => $attributeInstance->stopPropagation ?? false
|
||||
'stopPropagation' => $attributeInstance->stopPropagation ?? false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\EventBus;
|
||||
|
||||
interface Middleware
|
||||
|
||||
Reference in New Issue
Block a user