38 lines
989 B
PHP
38 lines
989 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace App\EventSubscriber;
|
||
|
|
|
||
|
|
use App\Event\TodoCompletedEvent;
|
||
|
|
use PhpQml\Bridge\PublisherInterface;
|
||
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Republishes TodoCompletedEvent on `app://event/todo-completed`.
|
||
|
|
* Auto-generated alongside the event class — wire `payload` to whatever
|
||
|
|
* shape you want QML clients to receive in the envelope's `data` field.
|
||
|
|
*/
|
||
|
|
final readonly class TodoCompletedSubscriber implements EventSubscriberInterface
|
||
|
|
{
|
||
|
|
public function __construct(
|
||
|
|
private PublisherInterface $publisher,
|
||
|
|
) {
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function getSubscribedEvents(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
TodoCompletedEvent::class => 'onTodoCompleted',
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
public function onTodoCompleted(TodoCompletedEvent $event): void
|
||
|
|
{
|
||
|
|
$this->publisher->publish('app://event/todo-completed', [
|
||
|
|
'op' => 'event',
|
||
|
|
'data' => $event->payload,
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|