From 7fa3a7343ed8e5422cf9fdd580364eb09259112e Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 26 Aug 2015 11:54:06 -0500 Subject: [PATCH 1/2] Compose an EmitterStack by default - It makes sense to compose an EmitterStack by default; that way, users of AppFactory can manipulate the emitter without needing to resort to direct instantiation. --- src/Application.php | 7 ++++--- test/ApplicationTest.php | 14 ++++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Application.php b/src/Application.php index c8062bd0..07fb8bc5 100644 --- a/src/Application.php +++ b/src/Application.php @@ -458,15 +458,16 @@ public function getFinalHandler(ResponseInterface $response = null) /** * Retrieve an emitter to use during run(). * - * If none was registered during instantiation, this will lazy-load a - * SapiEmitter instance. + * If none was registered during instantiation, this will lazy-load an + * EmitterStack composing an SapiEmitter instance. * * @return EmitterInterface */ public function getEmitter() { if (! $this->emitter) { - $this->emitter = new SapiEmitter; + $this->emitter = new Emitter\EmitterStack(); + $this->emitter->push(new SapiEmitter()); } return $this->emitter; } diff --git a/test/ApplicationTest.php b/test/ApplicationTest.php index a1079c34..2f9c4ebc 100644 --- a/test/ApplicationTest.php +++ b/test/ApplicationTest.php @@ -13,8 +13,10 @@ use PHPUnit_Framework_TestCase as TestCase; use Prophecy\Argument; use ReflectionProperty; +use Zend\Diactoros\Response\SapiEmitter; use Zend\Diactoros\ServerRequest as Request; use Zend\Expressive\Application; +use Zend\Expressive\Emitter\EmitterStack; use Zend\Expressive\Router\Route; use Zend\Expressive\Router\RouteResult; use Zend\Stratigility\Route as StratigilityRoute; @@ -260,11 +262,15 @@ public function testFinalHandlerIsUsedAtInvocationIfNoOutArgumentIsSupplied() $this->assertSame($finalResponse, $test); } - public function testComposesSapiEmitterByDefault() + public function testComposesEmitterStackWithSapiEmitterByDefault() { - $app = $this->getApp(); - $emitter = $app->getEmitter(); - $this->assertInstanceOf('Zend\Diactoros\Response\SapiEmitter', $emitter); + $app = $this->getApp(); + $stack = $app->getEmitter(); + $this->assertInstanceOf(EmitterStack::class, $stack); + + $this->assertCount(1, $stack); + $test = $stack->pop(); + $this->assertInstanceOf(SapiEmitter::class, $test); } public function testAllowsInjectingEmitterAtInstantiation() From a0de0bf38287017e0bffcbd00e3d4d5ae5813539 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 26 Aug 2015 11:55:27 -0500 Subject: [PATCH 2/2] Container does not need to inject an EmitterStack - Since it's now the default behavior. --- src/Container/ApplicationFactory.php | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/Container/ApplicationFactory.php b/src/Container/ApplicationFactory.php index e1a23e97..dc536a67 100644 --- a/src/Container/ApplicationFactory.php +++ b/src/Container/ApplicationFactory.php @@ -133,7 +133,7 @@ public function __invoke(ContainerInterface $container) $emitter = $container->has(EmitterInterface::class) ? $container->get(EmitterInterface::class) - : $this->createEmitterStack(); + : null; $app = new Application($router, $container, $finalHandler, $emitter); @@ -175,18 +175,6 @@ private function injectRoutes(Application $app, ContainerInterface $container) } } - /** - * Create the default emitter stack. - * - * @return EmitterStack - */ - private function createEmitterStack() - { - $emitter = new EmitterStack(); - $emitter->push(new SapiEmitter()); - return $emitter; - } - /** * Given a collection of middleware specifications, pipe them to the application. *