diff --git a/src/Twig/MercureExtension.php b/src/Twig/MercureExtension.php index efef176..ebf9852 100644 --- a/src/Twig/MercureExtension.php +++ b/src/Twig/MercureExtension.php @@ -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 */ -final class MercureExtension extends AbstractExtension +final class MercureExtension { private $hubRegistry; private $authorization; @@ -37,17 +36,13 @@ public function __construct(HubRegistry $hubRegistry, ?Authorization $authorizat $this->requestStack = $requestStack; } - 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, 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($topics = null, array $options = []): string { $hub = $options['hub'] ?? null;