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 diff --git a/src/App/src/Handler/HomePageHandler.php b/src/App/src/Handler/HomePageHandler.php index 03303d2..980adc5 100644 --- a/src/App/src/Handler/HomePageHandler.php +++ b/src/App/src/Handler/HomePageHandler.php @@ -11,31 +11,34 @@ 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 { - 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/', @@ -65,6 +68,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'; 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 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(