From fffce8505521b36fbcec83d6e6f75ca7e95dc2bd Mon Sep 17 00:00:00 2001 From: Geert Eltink Date: Mon, 5 Nov 2018 09:19:32 +0100 Subject: [PATCH 1/5] Add PHP-DI ContainerWrapper detection --- src/App/src/Handler/HomePageHandler.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/App/src/Handler/HomePageHandler.php b/src/App/src/Handler/HomePageHandler.php index 03303d2..cbdbf02 100644 --- a/src/App/src/Handler/HomePageHandler.php +++ b/src/App/src/Handler/HomePageHandler.php @@ -65,6 +65,7 @@ public function handle(ServerRequestInterface $request) : ResponseInterface $data['containerName'] = 'Symfony DI Container'; $data['containerDocs'] = 'https://symfony.com/doc/current/service_container.html'; break; + case 'Zend\DI\Config\ContainerWrapper': case 'DI\Container': $data['containerName'] = 'PHP-DI'; $data['containerDocs'] = 'http://php-di.org'; From dfc63deae696cfab03c1dffe4827353f550681d6 Mon Sep 17 00:00:00 2001 From: Geert Eltink Date: Mon, 5 Nov 2018 09:24:01 +0100 Subject: [PATCH 2/5] Update coding style --- src/App/src/Handler/HomePageHandler.php | 11 +++++++---- src/App/src/Handler/HomePageHandlerFactory.php | 4 +++- src/App/src/Handler/PingHandler.php | 2 ++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/App/src/Handler/HomePageHandler.php b/src/App/src/Handler/HomePageHandler.php index cbdbf02..40e51b2 100644 --- a/src/App/src/Handler/HomePageHandler.php +++ b/src/App/src/Handler/HomePageHandler.php @@ -11,26 +11,29 @@ use Zend\Diactoros\Response\JsonResponse; use Zend\Expressive\Plates\PlatesRenderer; use Zend\Expressive\Router; -use Zend\Expressive\Template; +use Zend\Expressive\Template\TemplateRendererInterface; use Zend\Expressive\Twig\TwigRenderer; use Zend\Expressive\ZendView\ZendViewRenderer; class HomePageHandler implements RequestHandlerInterface { + /** @var string */ private $containerName; + /** @var Router\RouterInterface */ private $router; + /** @var null|TemplateRendererInterface */ private $template; public function __construct( + string $containerName, Router\RouterInterface $router, - Template\TemplateRendererInterface $template = null, - string $containerName + ?TemplateRendererInterface $template = null ) { + $this->containerName = $containerName; $this->router = $router; $this->template = $template; - $this->containerName = $containerName; } public function handle(ServerRequestInterface $request) : ResponseInterface diff --git a/src/App/src/Handler/HomePageHandlerFactory.php b/src/App/src/Handler/HomePageHandlerFactory.php index 576e950..07a05f3 100644 --- a/src/App/src/Handler/HomePageHandlerFactory.php +++ b/src/App/src/Handler/HomePageHandlerFactory.php @@ -9,6 +9,8 @@ use Zend\Expressive\Router\RouterInterface; use Zend\Expressive\Template\TemplateRendererInterface; +use function get_class; + class HomePageHandlerFactory { public function __invoke(ContainerInterface $container) : RequestHandlerInterface @@ -18,6 +20,6 @@ public function __invoke(ContainerInterface $container) : RequestHandlerInterfac ? $container->get(TemplateRendererInterface::class) : null; - return new HomePageHandler($router, $template, get_class($container)); + return new HomePageHandler(get_class($container), $router, $template); } } diff --git a/src/App/src/Handler/PingHandler.php b/src/App/src/Handler/PingHandler.php index cd1c43d..ff52f9a 100644 --- a/src/App/src/Handler/PingHandler.php +++ b/src/App/src/Handler/PingHandler.php @@ -9,6 +9,8 @@ use Psr\Http\Server\RequestHandlerInterface; use Zend\Diactoros\Response\JsonResponse; +use function time; + class PingHandler implements RequestHandlerInterface { public function handle(ServerRequestInterface $request) : ResponseInterface From cd47f44bd686f965f0b1af33b78fd6d4b73cc3dd Mon Sep 17 00:00:00 2001 From: Geert Eltink Date: Mon, 5 Nov 2018 09:34:46 +0100 Subject: [PATCH 3/5] Fix homepage handler tests --- test/AppTest/Handler/HomePageHandlerTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/AppTest/Handler/HomePageHandlerTest.php b/test/AppTest/Handler/HomePageHandlerTest.php index e4ac5bd..3c128ab 100644 --- a/test/AppTest/Handler/HomePageHandlerTest.php +++ b/test/AppTest/Handler/HomePageHandlerTest.php @@ -32,9 +32,9 @@ protected function setUp() public function testReturnsJsonResponseWhenNoTemplateRendererProvided() { $homePage = new HomePageHandler( + get_class($this->container->reveal()), $this->router->reveal(), - null, - get_class($this->container->reveal()) + null ); $response = $homePage->handle( $this->prophesize(ServerRequestInterface::class)->reveal() @@ -51,9 +51,9 @@ public function testReturnsHtmlResponseWhenTemplateRendererProvided() ->willReturn(''); $homePage = new HomePageHandler( + get_class($this->container->reveal()), $this->router->reveal(), - $renderer->reveal(), - get_class($this->container->reveal()) + $renderer->reveal() ); $response = $homePage->handle( From 3bfeea4012963fc6f6fc3af508c1a9b7960804cd Mon Sep 17 00:00:00 2001 From: Geert Eltink Date: Mon, 5 Nov 2018 09:35:32 +0100 Subject: [PATCH 4/5] Properly check if there is a template instance --- src/App/src/Handler/HomePageHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/App/src/Handler/HomePageHandler.php b/src/App/src/Handler/HomePageHandler.php index 40e51b2..980adc5 100644 --- a/src/App/src/Handler/HomePageHandler.php +++ b/src/App/src/Handler/HomePageHandler.php @@ -38,7 +38,7 @@ public function __construct( public function handle(ServerRequestInterface $request) : ResponseInterface { - if (! $this->template) { + if ($this->template === null) { return new JsonResponse([ 'welcome' => 'Congratulations! You have installed the zend-expressive skeleton application.', 'docsUrl' => 'https://docs.zendframework.com/zend-expressive/', From 998d7b828d4ee00a325d06402fe18504e81742c0 Mon Sep 17 00:00:00 2001 From: Geert Eltink Date: Mon, 5 Nov 2018 09:44:13 +0100 Subject: [PATCH 5/5] Add changelog for #266 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5f23b7..799f0fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- Nothing. +- [#266](https://github.com/zendframework/zend-expressive-skeleton/pull/266) adds check for PHP-DI ContainerWrapper to the homepage handler ## 3.2.2 - 2018-11-05