Skip to content

Loading…

Fix Application::run() return values #4849

Closed
wants to merge 1 commit into from

3 participants

@weierophinney
Zend Framework member

This PR addresses concerns raised in #4831:

  • run() now always returns an Application instance; its docblock has been updated accordingly as well.
  • If an event returns a response object, it is pushed into the Application instance.
@weierophinney weierophinney [#4831] Fix run() return values
- Always return the application instance. (and fix docblock to indicate this)
- If an alternate response object is returned by an event, give it to
  the application instance.
5c70772
@Maks3w
Zend Framework member

Since introduces a BC Break Should this be scheudle for 2.3?

@weierophinney
Zend Framework member

@Maks3w We actually changed Application for 2.1 to return the Application instance -- but missed those few returns that occur due to short-circuiting. This just makes it consistent finally.

@Maks3w Maks3w was assigned
@Maks3w Maks3w closed this
@Maks3w
Zend Framework member

@reenl This will be released with 2.3

@reenl

Docs:

$response = $application->run();
$response->send();

2.2.1:
https://github.com/zendframework/zf2/blob/release-2.2.1/library/Zend/Mvc/Application.php#L324
return $this; // Zend\Mvc\Application

In this PR:
https://github.com/weierophinney/zf2/blob/5c70772642323e8d2f2665d5bb921095568e65ee/library/Zend/Mvc/Application.php#L38

 * <code>
 * $services = new Zend\ServiceManager\ServiceManager($servicesConfig);
 * $app      = new Application($appConfig, $services);
 * $app->bootstrap();
 * $response = $app->run();
 * $response->send();
 * </code>
@weierophinney
Zend Framework member

@reenl Those docs are generated from a tag. When the new code is released, new docs will be generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 18, 2013
  1. @weierophinney

    [#4831] Fix run() return values

    weierophinney committed
    - Always return the application instance. (and fix docblock to indicate this)
    - If an alternate response object is returned by an event, give it to
      the application instance.
Showing with 11 additions and 7 deletions.
  1. +6 −4 library/Zend/Mvc/Application.php
  2. +5 −3 tests/ZendTest/Mvc/ApplicationTest.php
View
10 library/Zend/Mvc/Application.php
@@ -268,7 +268,7 @@ public static function init($configuration = array())
* discovered controller, and controller class (if known).
* Typically, a handler should return a populated Response object
* that can be returned immediately.
- * @return ResponseInterface
+ * @return self
*/
public function run()
{
@@ -294,12 +294,13 @@ public function run()
$event->setTarget($this);
$event->setResponse($response);
$events->trigger(MvcEvent::EVENT_FINISH, $event);
- return $response;
+ $this->response = $response;
+ return $this;
}
if ($event->getError()) {
return $this->completeRequest($event);
}
- return $event->getResponse();
+ return $this;
}
if ($event->getError()) {
return $this->completeRequest($event);
@@ -314,7 +315,8 @@ public function run()
$event->setTarget($this);
$event->setResponse($response);
$events->trigger(MvcEvent::EVENT_FINISH, $event);
- return $response;
+ $this->response = $response;
+ return $this;
}
$response = $this->getResponse();
View
8 tests/ZendTest/Mvc/ApplicationTest.php
@@ -332,14 +332,15 @@ public function testAllowsReturningEarlyFromRouting()
});
$result = $this->application->run();
- $this->assertSame($response, $result);
+ $this->assertSame($this->application, $result);
+ $this->assertSame($response, $result->getResponse());
}
public function testControllerIsDispatchedDuringRun()
{
$this->setupPathController();
- $response = $this->application->run();
+ $response = $this->application->run()->getResponse();
$this->assertContains('PathController', $response->getContent());
$this->assertContains('dispatch', $response->toString());
}
@@ -496,7 +497,8 @@ public function testLocatorExceptionShouldTriggerDispatchError()
});
$result = $this->application->run();
- $this->assertSame($response, $result, var_export($result, 1));
+ $this->assertSame($this->application, $result, get_class($result));
+ $this->assertSame($response, $result->getResponse(), get_class($result));
}
/**
Something went wrong with that request. Please try again.