Files
php-qml/framework/php/src/Maker/templates/EventSubscriber.tpl.php

40 lines
1.0 KiB
PHP
Raw Normal View History

<?= "<?php\n" ?>
declare(strict_types=1);
namespace App\EventSubscriber;
use App\Event\<?= $event_short ?>;
use PhpQml\Bridge\PublisherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Republishes <?= $event_short ?> on `app://event/<?= $event_topic ?>`.
* 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 <?= $subscriber_short ?>
implements EventSubscriberInterface
{
public function __construct(
private PublisherInterface $publisher,
) {
}
public static function getSubscribedEvents(): array
{
return [
<?= $event_short ?>::class => '<?= $handler_method ?>',
];
}
public function <?= $handler_method ?>(<?= $event_short ?> $event): void
{
$this->publisher->publish('app://event/<?= $event_topic ?>', [
'op' => 'event',
'data' => $event->payload,
]);
}
}