Skip to content

Loading…

Controller action HttpResponse is not used by SendResponseListener #2981

Closed
wants to merge 1 commit into from

2 participants

@devosc

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 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
@devosc

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?

@weierophinney weierophinney added a commit that referenced this pull request
@weierophinney 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
@weierophinney weierophinney added a commit that referenced this pull request
@weierophinney weierophinney Merge branch 'hotfix/2981' into develop
Forward port #2981
0dcd8df
@weierophinney weierophinney added a commit that closed this pull request
@weierophinney weierophinney Merge branch 'hotfix/2981'
Close #2981
324592f
@weierophinney
Zend Framework member

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.

@ghost Unknown pushed a commit that referenced this pull request
@weierophinney 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
@ghost Unknown pushed a commit that referenced this pull request
@weierophinney weierophinney Merge branch 'hotfix/2981'
Close #2981
d8a736b
@ghost Unknown pushed a commit that referenced this pull request
@weierophinney 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
Commits on Nov 16, 2012
  1. @devosc

    Controller action HttpResponse is not used by SendResponseListener

    devosc committed
    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?
Showing with 1 addition and 0 deletions.
  1. +1 −0 library/Zend/Mvc/Application.php
View
1 library/Zend/Mvc/Application.php
@@ -299,6 +299,7 @@ public function run()
$response = $result->last();
if ($response instanceof ResponseInterface) {
$event->setTarget($this);
+ $event->setResponse($response);
$events->trigger(MvcEvent::EVENT_FINISH, $event);
return $response;
}
Something went wrong with that request. Please try again.