36 lines
817 B
PHP
36 lines
817 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace PhpQml\Bridge;
|
||
|
|
|
||
|
|
use Symfony\Component\Mercure\HubInterface;
|
||
|
|
use Symfony\Component\Mercure\Update;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Publishes envelopes onto the bridge's Mercure hub.
|
||
|
|
*
|
||
|
|
* Topic conventions and envelope shape are defined in PLAN.md §4.
|
||
|
|
* Reactive-model-aware helpers (publishModelUpdate, etc.) arrive with
|
||
|
|
* the model layer in Phase 2.
|
||
|
|
*/
|
||
|
|
final readonly class Publisher
|
||
|
|
{
|
||
|
|
public function __construct(
|
||
|
|
private HubInterface $hub,
|
||
|
|
) {
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param array<string, mixed> $envelope
|
||
|
|
*/
|
||
|
|
public function publish(string $topic, array $envelope, bool $private = false): string
|
||
|
|
{
|
||
|
|
return $this->hub->publish(new Update(
|
||
|
|
$topic,
|
||
|
|
json_encode($envelope, JSON_THROW_ON_ERROR),
|
||
|
|
$private,
|
||
|
|
));
|
||
|
|
}
|
||
|
|
}
|