Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions src/Twig/MercureExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Mercure\Authorization;
use Symfony\Component\Mercure\HubRegistry;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
use Twig\Attribute\AsTwigFunction;

/**
* Registers the Twig helper function.
*
* @author Kévin Dunglas <kevin@dunglas.fr>
*/
final class MercureExtension extends AbstractExtension
final class MercureExtension
{
public function __construct(
private readonly HubRegistry $hubRegistry,
Expand All @@ -33,17 +32,13 @@ public function __construct(
) {
}

public function getFunctions(): array
{
return [new TwigFunction('mercure', [$this, 'mercure'])];
}

/**
* @param string|string[]|null $topics A topic or an array of topics to subscribe for. If this parameter is omitted or `null` is passed, the URL of the hub will be returned (useful for publishing in JavaScript).
* @param array{subscribe?: string[]|string, publish?: string[]|string, additionalClaims?: array<string, mixed>, lastEventId?: string, hub?: string} $options The options to pass to the JWT factory
*
* @return string The URL of the hub with the appropriate "topic" query parameters (if any)
*/
#[AsTwigFunction('mercure')]
public function mercure(string|array|null $topics = null, array $options = []): string
{
$hub = $options['hub'] ?? null;
Expand Down