Skip to content
This repository

Controller action HttpResponse is not used by SendResponseListener #2981

Closed
wants to merge 1 commit into from

2 participants

Matthew Weier O'Phinney

SendResponseListener is getting the response from the event via the getResponse, whereas the actual HttpResponse returned by the controller action is stored as the result for that event.

public function indexAction()
{
    //return new ViewModel();
    $response = new \Zend\Http\PhpEnvironment\Response();
    $response->setContent('OK');

    return $response;
}

This is a little confusing given that the AbstractController will stop dispatching when the returned value is a Response instance.

    $result = $this->getEventManager()->trigger(MvcEvent::EVENT_DISPATCH, $e, function($test) {
        return ($test instanceof Response);
    });

And then the SendResponseLister is pulling from getResponse()

public function sendResponse(MvcEvent $e)
{
    $response = $e->getResponse();
    var_dump($response, $e->getResult()); //these instances differ

It seems like the Mvc\Application should set the result Response as the event response?

    $response = $result->last();
    if ($response instanceof ResponseInterface) {
        $event->setTarget($this);
        $event->setResponse($response); //set response for SendResponseListener
devosc Controller action HttpResponse is not used by SendResponseListener
SendResponseListener is getting the response from the event via the getResponse, whereas the actual HttpResponse returned by the controller action is stored as the result for that event.

    public function indexAction()
    {
        //return new ViewModel();
        $response = new \Zend\Http\PhpEnvironment\Response();
        $response->setContent('OK');

        return $response;
    }

This is a little confusing given that the AbstractController will stop dispatching when the returned value is a Response instance.

        $result = $this->getEventManager()->trigger(MvcEvent::EVENT_DISPATCH, $e, function($test) {
            return ($test instanceof Response);
        });


And then the SendResponseLister is pulling from getResponse()

    public function sendResponse(MvcEvent $e)
    {
        $response = $e->getResponse();
        var_dump($response, $e->getResult()); //these instances differ



It seems like the Mvc\Application should set the result Response as the event response?

        $response = $result->last();
        if ($response instanceof ResponseInterface) {
            $event->setTarget($this);
            $event->setResponse($response); //set response for SendResponseListener


Or is this an implementation detail rather than a bug?
96a2eb9

Assuming this is a valid issue, after reading issue #2651, the same problem occurs for the route event. So either the response needs to be set as the event response there also, or alternatively, set the response into the event object in the short circuit callback instead?

Matthew Weier O'Phinney weierophinney referenced this pull request from a commit
Matthew Weier O'Phinney weierophinney [#2981] test, and apply to route event
- Added unit tests to ensure response is reset in event for both route
  and dispatch short-circuits
- Ensured that response is reset after a routing short circuit
480d8b6
Matthew Weier O'Phinney

Added tests for both the cases of route and dispatch short-circuits, and also added the response to the event following a route short circuit.

Deleted user Unknown referenced this pull request from a commit
Matthew Weier O'Phinney weierophinney [#2981] test, and apply to route event
- Added unit tests to ensure response is reset in event for both route
  and dispatch short-circuits
- Ensured that response is reset after a routing short circuit
1de8886
Deleted user Unknown referenced this pull request from a commit
Matthew Weier O'Phinney weierophinney Merge branch 'hotfix/2981'
Close #2981
d8a736b
Deleted user Unknown referenced this pull request from a commit
Matthew Weier O'Phinney weierophinney Merge branch 'hotfix/2981' into develop
Forward port #2981
ad7b794
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Nov 16, 2012
devosc Controller action HttpResponse is not used by SendResponseListener
SendResponseListener is getting the response from the event via the getResponse, whereas the actual HttpResponse returned by the controller action is stored as the result for that event.

    public function indexAction()
    {
        //return new ViewModel();
        $response = new \Zend\Http\PhpEnvironment\Response();
        $response->setContent('OK');

        return $response;
    }

This is a little confusing given that the AbstractController will stop dispatching when the returned value is a Response instance.

        $result = $this->getEventManager()->trigger(MvcEvent::EVENT_DISPATCH, $e, function($test) {
            return ($test instanceof Response);
        });


And then the SendResponseLister is pulling from getResponse()

    public function sendResponse(MvcEvent $e)
    {
        $response = $e->getResponse();
        var_dump($response, $e->getResult()); //these instances differ



It seems like the Mvc\Application should set the result Response as the event response?

        $response = $result->last();
        if ($response instanceof ResponseInterface) {
            $event->setTarget($this);
            $event->setResponse($response); //set response for SendResponseListener


Or is this an implementation detail rather than a bug?
96a2eb9
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 1 addition and 0 deletions. Show diff stats Hide diff stats

  1. +1 0  library/Zend/Mvc/Application.php
1  library/Zend/Mvc/Application.php
@@ -299,6 +299,7 @@ public function run()
299 299 $response = $result->last();
300 300 if ($response instanceof ResponseInterface) {
301 301 $event->setTarget($this);
  302 + $event->setResponse($response);
302 303 $events->trigger(MvcEvent::EVENT_FINISH, $event);
303 304 return $response;
304 305 }

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.