Commit 24bce51f authored by Fabien Potencier's avatar Fabien Potencier

removed the deprecated TwigCoreExtension class

parent a4c7c51f
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Provider;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
/**
* Twig extension.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated deprecated since 1.2, will be removed in 1.3. Use HttpFragmentServiceProvider instead
*/
class TwigCoreExtension extends \Twig_Extension
{
public function getFunctions()
{
return array(
'render' => new \Twig_Function_Method($this, 'render', array('needs_environment' => true, 'is_safe' => array('html'))),
);
}
public function render(\Twig_Environment $twig, $uri)
{
$globals = $twig->getGlobals();
$request = $globals['app']['request'];
$subRequest = Request::create($uri, 'get', array(), $request->cookies->all(), array(), $request->server->all());
if ($request->getSession()) {
$subRequest->setSession($request->getSession());
}
$response = $globals['app']->handle($subRequest, HttpKernelInterface::SUB_REQUEST, false);
if (!$response->isSuccessful()) {
throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %s).', $request->getUri(), $response->getStatusCode()));
}
return $response->getContent();
}
public function getName()
{
return 'silex';
}
}
...@@ -68,9 +68,6 @@ class TwigServiceProvider implements ServiceProviderInterface ...@@ -68,9 +68,6 @@ class TwigServiceProvider implements ServiceProviderInterface
$app['fragment.renderer.hinclude']->setTemplating($twig); $app['fragment.renderer.hinclude']->setTemplating($twig);
$twig->addExtension(new HttpKernelExtension($app['fragment.handler'])); $twig->addExtension(new HttpKernelExtension($app['fragment.handler']));
} else {
// fallback for BC, to be removed in 1.3
$twig->addExtension(new TwigCoreExtension());
} }
if (isset($app['form.factory'])) { if (isset($app['form.factory'])) {
......
...@@ -39,30 +39,6 @@ class TwigServiceProviderTest extends \PHPUnit_Framework_TestCase ...@@ -39,30 +39,6 @@ class TwigServiceProviderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('Hello john!', $response->getContent()); $this->assertEquals('Hello john!', $response->getContent());
} }
public function testRenderFunction()
{
$app = new Application();
$app->register(new TwigServiceProvider(), array(
'twig.templates' => array(
'hello' => '{{ render("/foo") }}',
'foo' => 'foo',
),
));
$app->get('/hello', function () use ($app) {
return $app['twig']->render('hello');
});
$app->get('/foo', function () use ($app) {
return $app['twig']->render('foo');
});
$request = Request::create('/hello');
$response = $app->handle($request);
$this->assertEquals('foo', $response->getContent());
}
public function testLoaderPriority() public function testLoaderPriority()
{ {
$app = new Application(); $app = new Application();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment