diff --git a/src/Application/ErrorPresenter.php b/src/Application/ErrorPresenter.php index a19d204e3..9553cce49 100644 --- a/src/Application/ErrorPresenter.php +++ b/src/Application/ErrorPresenter.php @@ -41,9 +41,9 @@ public function run(Application\Request $request) $this->logger->log($e, ILogger::EXCEPTION); } } - ob_start(); - require __DIR__ . '/templates/error.phtml'; - return new Application\Responses\TextResponse(ob_get_clean()); + return new Application\Responses\CallbackResponse(function () use ($code) { + require __DIR__ . '/templates/error.phtml'; + }); } } diff --git a/src/Application/IRouteList.php b/src/Application/IRouteList.php new file mode 100644 index 000000000..e7a771aa9 --- /dev/null +++ b/src/Application/IRouteList.php @@ -0,0 +1,23 @@ +<?php + +/** + * This file is part of the Nette Framework (http://nette.org) + * Copyright (c) 2004 David Grudl (http://davidgrudl.com) + */ + +namespace Nette\Application; + +use Nette; + + +/** + * Routes collection. + */ +interface IRouteList extends \IteratorAggregate +{ + /** + * @return string + */ + function getModule(); + +} diff --git a/src/Application/Responses/CallbackResponse.php b/src/Application/Responses/CallbackResponse.php new file mode 100644 index 000000000..90d1380e8 --- /dev/null +++ b/src/Application/Responses/CallbackResponse.php @@ -0,0 +1,37 @@ +<?php + +/** + * This file is part of the Nette Framework (http://nette.org) + * Copyright (c) 2004 David Grudl (http://davidgrudl.com) + */ + +namespace Nette\Application\Responses; + +use Nette; + + +/** + * Callback response. + */ +class CallbackResponse extends Nette\Object implements Nette\Application\IResponse +{ + /** @var callable */ + private $callback; + + + public function __construct(callable $callback) + { + $this->callback = $callback; + } + + + /** + * Sends response to output. + * @return void + */ + public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse) + { + call_user_func($this->callback, $httpRequest, $httpResponse); + } + +} diff --git a/src/Application/Routers/RouteList.php b/src/Application/Routers/RouteList.php index 912c65058..55f1d6f82 100644 --- a/src/Application/Routers/RouteList.php +++ b/src/Application/Routers/RouteList.php @@ -13,7 +13,7 @@ /** * The router broker. */ -class RouteList extends Nette\Utils\ArrayList implements Nette\Application\IRouter +class RouteList extends Nette\Utils\ArrayList implements Nette\Application\IRouter, Nette\Application\IRouteList { /** @var array */ private $cachedRoutes; diff --git a/src/Bridges/ApplicationTracy/RoutingPanel.php b/src/Bridges/ApplicationTracy/RoutingPanel.php index 83468ef5a..9753ea564 100644 --- a/src/Bridges/ApplicationTracy/RoutingPanel.php +++ b/src/Bridges/ApplicationTracy/RoutingPanel.php @@ -96,7 +96,7 @@ public function getPanel() */ private function analyse($router, $module = '') { - if ($router instanceof Routers\RouteList) { + if ($router instanceof Nette\Application\IRouteList) { foreach ($router as $subRouter) { $this->analyse($subRouter, $module . $router->getModule()); } diff --git a/tests/Application/CallbackResponse.phpt b/tests/Application/CallbackResponse.phpt new file mode 100644 index 000000000..83ac423f8 --- /dev/null +++ b/tests/Application/CallbackResponse.phpt @@ -0,0 +1,21 @@ +<?php + +/** + * Test: Nette\Application\Responses\CallbackResponse. + */ + +use Nette\Application\Responses\CallbackResponse; +use Nette\Http; +use Tester\Assert; + + +require __DIR__ . '/../bootstrap.php'; + + +test(function () { + $response = new CallbackResponse(function (Http\IRequest $request, Http\IResponse $response) use (& $ok) { + $ok = TRUE; + }); + $response->send(new Http\Request(new Http\UrlScript), new Http\Response); + Assert::true($ok); +});