src/Mercure/EventListener/AddLinkHeaderListener.php
public function onKernelResponse(FilterResponseEvent $event): void
    {
        $link = new Link('mercure', $this->hub);

        $attributes = $event->getRequest()->attributes;
        if (
            null === ($resourceClass = $attributes->get('_api_resource_class')) ||
            false === $this->resourceMetadataFactory->create($resourceClass)->getAttribute('mercure', false)
        ) {
            return;
        }

        if (null === $linkProvider = $attributes->get('_links')) {
            $attributes->set('_links', new GenericLinkProvider([$link]));

            return;
        }

        $attributes->set('_links', $linkProvider->withLink($link));
    }
public function onKernelResponse(FilterResponseEvent $event): void
    {
        $link = new Link('mercure', $this->hub);

        $attributes = $event->getRequest()->attributes;
        if (
            null === ($resourceClass = $attributes->get('_api_resource_class')) ||
            false === $this->resourceMetadataFactory->create($resourceClass)->getAttribute('mercure', false)
        ) {
            return;
        }

        if (null === $linkProvider = $attributes->get('_links')) {
            $attributes->set('_links', new GenericLinkProvider([$link]));

            return;
        }

        $attributes->set('_links', $linkProvider->withLink($link));
    }
public function onKernelResponse ( FilterResponseEvent $ event ) : void { $ link = new Link ( 'mercure' , $ this -> hub ) ; $ attributes = $ event -> getRequest ( ) -> attributes ; if ( null === ( $ resourceClass = $ attributes -> get ( '_api_resource_class' ) ) || false === $ this -> resourceMetadataFactory -> create ( $ resourceClass ) -> getAttribute ( 'mercure' , false ) ) { return ; } if ( null === $ linkProvider = $ attributes -> get ( '_links' ) ) { $ attributes -> set ( '_links' , new GenericLinkProvider ( [ $ link ] ) ) ; return ; } $ attributes -> set ( '_links' , $ linkProvider -> withLink ( $ link ) ) ; }
Sends the Mercure header on each response.
Sends the Mercure header on each response .