Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/266'
Browse files Browse the repository at this point in the history
Close #266
  • Loading branch information
geerteltink committed Nov 5, 2018
2 parents ec909e5 + 998d7b8 commit 296952d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -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

Expand Down
14 changes: 9 additions & 5 deletions src/App/src/Handler/HomePageHandler.php
Expand Up @@ -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/',
Expand Down Expand Up @@ -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';
Expand Down
4 changes: 3 additions & 1 deletion src/App/src/Handler/HomePageHandlerFactory.php
Expand Up @@ -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
Expand All @@ -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);
}
}
2 changes: 2 additions & 0 deletions src/App/src/Handler/PingHandler.php
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/AppTest/Handler/HomePageHandlerTest.php
Expand Up @@ -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()
Expand All @@ -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(
Expand Down

0 comments on commit 296952d

Please sign in to comment.