Add support for custom output providers like Slim Framework

This commit is contained in:
Matias Griese
2017-04-21 11:22:08 +03:00
parent 7fc92dcaa2
commit aee07203a2
2 changed files with 18 additions and 4 deletions

View File

@@ -127,10 +127,16 @@ class Grav extends Container
});
}
// Set the header type
$this->header();
$output = $this->output;
// Support for custom output providers like Slim Framework.
if (!$output instanceof \Psr\Http\Message\ResponseInterface) {
// Set the header type
$this->header();
echo $output;
}
echo $this->output;
$debugger->render();
$this->fireEvent('onOutputRendered');

View File

@@ -8,6 +8,8 @@
namespace Grav\Common\Service;
use Grav\Common\Page\Page;
use Grav\Common\Twig\Twig;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
@@ -16,7 +18,13 @@ class OutputServiceProvider implements ServiceProviderInterface
public function register(Container $container)
{
$container['output'] = function ($c) {
return $c['twig']->processSite($c['page']->templateFormat());
/** @var Twig $twig */
$twig = $c['twig'];
/** @var Page $page */
$page = $c['page'];
return $twig->processSite($page->templateFormat());
};
}
}