Compare commits

...

2 Commits

Author SHA1 Message Date
Adrian 565c0315d3 TemplateRenderer which is used for 404 errors 2016-10-25 11:32:51 +02:00
Adrian cb3dab1a64 Add Whoops error handler 2016-10-25 11:18:34 +02:00
3 changed files with 44 additions and 0 deletions

View File

@ -5,6 +5,7 @@
} }
}, },
"require": { "require": {
"filp/whoops": "^2.1",
"xtreamwayz/pimple-container-interop": "^1.0", "xtreamwayz/pimple-container-interop": "^1.0",
"zendframework/zend-expressive": "^1.0", "zendframework/zend-expressive": "^1.0",
"zendframework/zend-expressive-fastroute": "^1.2", "zendframework/zend-expressive-fastroute": "^1.2",

View File

@ -2,6 +2,7 @@
use Test\App\HomeAction; use Test\App\HomeAction;
use Test\App\HomeFactory; use Test\App\HomeFactory;
use Test\App\DummyRenderer;
use Xtreamwayz\Pimple\Container; use Xtreamwayz\Pimple\Container;
use Zend\Expressive\Application; use Zend\Expressive\Application;
use Zend\Expressive\Container\ApplicationFactory; use Zend\Expressive\Container\ApplicationFactory;
@ -11,6 +12,7 @@ use Zend\Expressive\Helper\UrlHelperMiddleware;
use Zend\Expressive\Helper\UrlHelperMiddlewareFactory; use Zend\Expressive\Helper\UrlHelperMiddlewareFactory;
use Zend\Expressive\Router\FastRouteRouter; use Zend\Expressive\Router\FastRouteRouter;
use Zend\Expressive\Router\RouterInterface; use Zend\Expressive\Router\RouterInterface;
use Zend\Expressive\Template\TemplateRendererInterface;
$c = new Container; $c = new Container;
@ -20,6 +22,12 @@ $c[RouterInterface::class] = function () { return new FastRouteRouter; };
$c[UrlHelper::class] = new UrlHelperFactory; $c[UrlHelper::class] = new UrlHelperFactory;
$c[UrlHelperMiddleware::class] = new UrlHelperMiddlewareFactory; $c[UrlHelperMiddleware::class] = new UrlHelperMiddlewareFactory;
$c[HomeAction::class] = new HomeFactory; $c[HomeAction::class] = new HomeFactory;
$c[TemplateRendererInterface::class] = function () { return new DummyRenderer; };
$c['Zend\Expressive\Whoops'] = function () { return new Whoops\Run; };
$c['Zend\Expressive\WhoopsPageHandler'] = function () { return new Whoops\Handler\PrettyPageHandler; };
$c['Zend\Expressive\FinalHandler'] = new Zend\Expressive\Container\WhoopsErrorHandlerFactory;
$c[Application::class] = new ApplicationFactory; $c[Application::class] = new ApplicationFactory;
return $c; return $c;

View File

@ -0,0 +1,35 @@
<?php
namespace Test\App;
use Zend\Expressive\Template\TemplateRendererInterface;
class DummyRenderer
implements TemplateRendererInterface
{
protected $paths = array();
public function render($name, $params = array())
{
$params = print_r(['params' => $params, 'paths' => $this->paths], true);
$params = str_replace("\n", "<br/>\n", $params);
$params = str_replace(" ", "&ensp;", $params);
return "Render template '$name'<br/>Params: $params";
}
public function addPath($path, $namespace = null)
{
if ($namespace !== null) $namespace .= '::';
$this->paths[] = $namespace . $path;
}
public function getPaths()
{
return $this->paths;
}
public function addDefaultParam($templateName, $param, $value)
{
throw new \RuntimeException('Not implemented');
}
}