v0.2.0 (7/N): make:bridge:event maker
Implements PLAN.md §8's third makers-table row. Single-command path
from a PHP domain event to a QML signal-handler:
- src/Event/<Name>Event.php — readonly value object stub
- src/EventSubscriber/<Name>Subscriber.php — listens to the event,
republishes via PublisherInterface on app://event/<kebab-name>
with op:"event"
- {qml_path}/<Name>EventHandler.qml — MercureClient bound to the
topic, re-emits the envelope's data as a typed signal
Stub uses an `array $payload` field so the user can substitute typed
properties for whatever shape they need. Subscriber example uses the
PublisherInterface contract from chunk 1; QML stub uses MercureClient
+ BackendConnection both already shipping.
Wired into services.yaml's when@dev block (autoconfigure picks up
maker.command tag, same pattern as existing BridgeResourceMaker /
BridgeWindowMaker). Three new snapshot baselines plus a snapshot
runner extension exercising the new maker against the same Todo /
TodoCompleted naming the existing baselines use.
End-to-end verified locally: maker output matches baselines, dev
container compiles, listing make:bridge:* shows the new command.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
39
framework/php/src/Maker/templates/EventSubscriber.tpl.php
Normal file
39
framework/php/src/Maker/templates/EventSubscriber.tpl.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?= "<?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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user