- Add DISCOVERY_LOG_LEVEL=debug - Add DISCOVERY_SHOW_PROGRESS=true - Temporary changes for debugging InitializerProcessor fixes on production
50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\Database\Events;
|
|
|
|
use App\Framework\Core\ValueObjects\Timestamp;
|
|
|
|
/**
|
|
* Event that is fired when an entity is loaded from database
|
|
*/
|
|
final readonly class EntityLoadedEvent
|
|
{
|
|
public Timestamp $timestamp;
|
|
|
|
public function __construct(
|
|
public object $entity,
|
|
public string $entityClass,
|
|
public mixed $entityId,
|
|
public array $loadedData = [],
|
|
public bool $wasLazy = false,
|
|
?Timestamp $timestamp = null,
|
|
) {
|
|
$this->timestamp = $timestamp ?? Timestamp::now();
|
|
}
|
|
|
|
/**
|
|
* Check if this event is for a specific entity class
|
|
*/
|
|
public function isEntityOfType(string $expectedClass): bool
|
|
{
|
|
return $this->entityClass === $expectedClass || $this->entity instanceof $expectedClass;
|
|
}
|
|
|
|
/**
|
|
* Get event metadata
|
|
*/
|
|
public function getEventData(): array
|
|
{
|
|
return [
|
|
'event_type' => 'entity_loaded',
|
|
'entity_class' => $this->entityClass,
|
|
'entity_id' => $this->entityId,
|
|
'timestamp' => $this->timestamp->toFloat(),
|
|
'was_lazy' => $this->wasLazy,
|
|
'loaded_data' => $this->loadedData,
|
|
];
|
|
}
|
|
}
|