src/Graviton/RabbitMqBundle/Listener/EventStatusLinkResponseListener.php
public function onKernelResponse(FilterResponseEvent $event)
    {
        /**
         * @var Response $response
         */
        $response = $event->getResponse();

        // exit if not master request, uninteresting method or an error occurred
        if (!$event->isMasterRequest() || $this->isNotConcerningRequest() || !$response->isSuccessful()) {
            return;
        }

        // we can always safely call this, it doesn't need much resources.
        // only if we have subscribers, it will create more load as it persists an EventStatus
        $queueEvent = $this->createQueueEventObject();

        if (!empty($queueEvent->getStatusurl()) && !empty($queueEvent->getEvent())) {
            $linkHeader = LinkHeader::fromResponse($response);
            $linkHeader->add(
                new LinkHeaderItem(
                    $queueEvent->getStatusurl(),
                    array('rel' => 'eventStatus')
                )
            );

            $response->headers->set(
                'Link',
                (string) $linkHeader
            );
        }

        // let's send it to the queue(s) if appropriate
        if (!empty($queueEvent->getEvent())) {
            $queuesForEvent = $this->getSubscribedWorkerIds($queueEvent);

            // if needed and activated, change urls relative to workers
            if (!empty($queuesForEvent) && $this->workerRelativeUrl instanceof Uri) {
                $queueEvent = $this->getWorkerQueueEvent($queueEvent);
            }

            foreach ($queuesForEvent as $queueForEvent) {
                // declare the Queue for the Event if its not there already declared
                $this->rabbitMqProducer->getChannel()->queue_declare($queueForEvent, false, true, false, false);
                $this->rabbitMqProducer->publish(json_encode($queueEvent), $queueForEvent);
            }
        }
    }
public function onKernelResponse(FilterResponseEvent $event)
    {
        /**
         * @var Response $response
         */
        $response = $event->getResponse();

        // exit if not master request, uninteresting method or an error occurred
        if (!$event->isMasterRequest() || $this->isNotConcerningRequest() || !$response->isSuccessful()) {
            return;
        }

        // we can always safely call this, it doesn't need much resources.
        // only if we have subscribers, it will create more load as it persists an EventStatus
        $queueEvent = $this->createQueueEventObject();

        if (!empty($queueEvent->getStatusurl()) && !empty($queueEvent->getEvent())) {
            $linkHeader = LinkHeader::fromResponse($response);
            $linkHeader->add(
                new LinkHeaderItem(
                    $queueEvent->getStatusurl(),
                    array('rel' => 'eventStatus')
                )
            );

            $response->headers->set(
                'Link',
                (string) $linkHeader
            );
        }

        // let's send it to the queue(s) if appropriate
        if (!empty($queueEvent->getEvent())) {
            $queuesForEvent = $this->getSubscribedWorkerIds($queueEvent);

            // if needed and activated, change urls relative to workers
            if (!empty($queuesForEvent) && $this->workerRelativeUrl instanceof Uri) {
                $queueEvent = $this->getWorkerQueueEvent($queueEvent);
            }

            foreach ($queuesForEvent as $queueForEvent) {
                // declare the Queue for the Event if its not there already declared
                $this->rabbitMqProducer->getChannel()->queue_declare($queueForEvent, false, true, false, false);
                $this->rabbitMqProducer->publish(json_encode($queueEvent), $queueForEvent);
            }
        }
    }
public function onKernelResponse ( FilterResponseEvent $ event ) { /**
         * @var Response $response
         */ $ response = $ event -> getResponse ( ) ; // exit if not master request, uninteresting method or an error occurred if ( ! $ event -> isMasterRequest ( ) || $ this -> isNotConcerningRequest ( ) || ! $ response -> isSuccessful ( ) ) { return ; } // we can always safely call this, it doesn't need much resources. // only if we have subscribers, it will create more load as it persists an EventStatus $ queueEvent = $ this -> createQueueEventObject ( ) ; if ( ! empty ( $ queueEvent -> getStatusurl ( ) ) && ! empty ( $ queueEvent -> getEvent ( ) ) ) { $ linkHeader = LinkHeader :: fromResponse ( $ response ) ; $ linkHeader -> add ( new LinkHeaderItem ( $ queueEvent -> getStatusurl ( ) , array ( 'rel' => 'eventStatus' ) ) ) ; $ response -> headers -> set ( 'Link' , ( string ) $ linkHeader ) ; } // let's send it to the queue(s) if appropriate if ( ! empty ( $ queueEvent -> getEvent ( ) ) ) { $ queuesForEvent = $ this -> getSubscribedWorkerIds ( $ queueEvent ) ; // if needed and activated, change urls relative to workers if ( ! empty ( $ queuesForEvent ) && $ this -> workerRelativeUrl instanceof Uri ) { $ queueEvent = $ this -> getWorkerQueueEvent ( $ queueEvent ) ; } foreach ( $ queuesForEvent as $ queueForEvent ) { // declare the Queue for the Event if its not there already declared $ this -> rabbitMqProducer -> getChannel ( ) -> queue_declare ( $ queueForEvent , false , true , false , false ) ; $ this -> rabbitMqProducer -> publish ( json_encode ( $ queueEvent ) , $ queueForEvent ) ; } } }
add a rel=eventStatus Link header to the response if necessary

@param FilterResponseEvent $event response listener event

@return void
add a rel = eventStatus Link header to the response if necessary