src/Graviton/RestBundle/Listener/LinkHeaderResponseListener.php
public function onKernelResponse(FilterResponseEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        $response = $event->getResponse();
        $request = $event->getRequest();

        // extract various info from route
        $routeName = $request->get('_route');
        $routeParts = explode('.', $routeName);
        $routeType = end($routeParts);

        $this->linkHeader = LinkHeader::fromResponse($response);

        // add common headers
        $this->addCommonHeaders($request, $response);

        // add self Link header
        $selfUrl = $this->addSelfLinkHeader($routeName, $routeType, $request);
        // dispatch this!

        // add paging Link element when applicable
        if ($routeType == 'all' && $request->attributes->get('paging')) {
            $this->generatePagingLinksHeaders($routeName, $request, $response);
        }

        // add schema link header element
        $this->generateSchemaLinkHeader($routeName, $request, $response);

        // finally set link header
        $response->headers->set(
            'Link',
            (string) $this->linkHeader
        );

        $event->setResponse($response);

        // dispatch the "selfaware" event
        $event->getRequest()->attributes->set('selfLink', $selfUrl);
        $dispatcher->dispatch('graviton.rest.response.selfaware', $event);
    }
public function onKernelResponse(FilterResponseEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        $response = $event->getResponse();
        $request = $event->getRequest();

        // extract various info from route
        $routeName = $request->get('_route');
        $routeParts = explode('.', $routeName);
        $routeType = end($routeParts);

        $this->linkHeader = LinkHeader::fromResponse($response);

        // add common headers
        $this->addCommonHeaders($request, $response);

        // add self Link header
        $selfUrl = $this->addSelfLinkHeader($routeName, $routeType, $request);
        // dispatch this!

        // add paging Link element when applicable
        if ($routeType == 'all' && $request->attributes->get('paging')) {
            $this->generatePagingLinksHeaders($routeName, $request, $response);
        }

        // add schema link header element
        $this->generateSchemaLinkHeader($routeName, $request, $response);

        // finally set link header
        $response->headers->set(
            'Link',
            (string) $this->linkHeader
        );

        $event->setResponse($response);

        // dispatch the "selfaware" event
        $event->getRequest()->attributes->set('selfLink', $selfUrl);
        $dispatcher->dispatch('graviton.rest.response.selfaware', $event);
    }
public function onKernelResponse ( FilterResponseEvent $ event , $ eventName , EventDispatcherInterface $ dispatcher ) { $ response = $ event -> getResponse ( ) ; $ request = $ event -> getRequest ( ) ; // extract various info from route $ routeName = $ request -> get ( '_route' ) ; $ routeParts = explode ( '.' , $ routeName ) ; $ routeType = end ( $ routeParts ) ; $ this -> linkHeader = LinkHeader :: fromResponse ( $ response ) ; // add common headers $ this -> addCommonHeaders ( $ request , $ response ) ; // add self Link header $ selfUrl = $ this -> addSelfLinkHeader ( $ routeName , $ routeType , $ request ) ; // dispatch this! // add paging Link element when applicable if ( $ routeType == 'all' && $ request -> attributes -> get ( 'paging' ) ) { $ this -> generatePagingLinksHeaders ( $ routeName , $ request , $ response ) ; } // add schema link header element $ this -> generateSchemaLinkHeader ( $ routeName , $ request , $ response ) ; // finally set link header $ response -> headers -> set ( 'Link' , ( string ) $ this -> linkHeader ) ; $ event -> setResponse ( $ response ) ; // dispatch the "selfaware" event $ event -> getRequest ( ) -> attributes -> set ( 'selfLink' , $ selfUrl ) ; $ dispatcher -> dispatch ( 'graviton.rest.response.selfaware' , $ event ) ; }
add our Link header items

@param FilterResponseEvent      $event      response listener event
@param string                   $eventName  event name
@param EventDispatcherInterface $dispatcher dispatcher

@return void
add our Link header items