Commit 29013a9f authored by Fabien Potencier's avatar Fabien Potencier

removed deprecated class

parent 4c01a361
...@@ -4,6 +4,7 @@ Changelog ...@@ -4,6 +4,7 @@ Changelog
1.3.0 (2015-XX-XX) 1.3.0 (2015-XX-XX)
------------------ ------------------
* removed deprecated TwigCoreExtension class (register the new HttpFragmentServiceProvider instead)
* bumped minimum version of PHP to 5.3.9 * bumped minimum version of PHP to 5.3.9
1.2.3 (2015-01-20) 1.2.3 (2015-01-20)
......
<?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'])) {
......
...@@ -13,6 +13,7 @@ namespace Silex\Tests\Provider; ...@@ -13,6 +13,7 @@ namespace Silex\Tests\Provider;
use Silex\Application; use Silex\Application;
use Silex\Provider\TwigServiceProvider; use Silex\Provider\TwigServiceProvider;
use Silex\Provider\HttpFragmentServiceProvider;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
/** /**
...@@ -41,8 +42,13 @@ class TwigServiceProviderTest extends \PHPUnit_Framework_TestCase ...@@ -41,8 +42,13 @@ class TwigServiceProviderTest extends \PHPUnit_Framework_TestCase
public function testRenderFunction() public function testRenderFunction()
{ {
if (!class_exists('Symfony\Component\HttpFoundation\RequestStack')) {
$this->markTestSkipped();
}
$app = new Application(); $app = new Application();
$app->register(new HttpFragmentServiceProvider());
$app->register(new TwigServiceProvider(), array( $app->register(new TwigServiceProvider(), array(
'twig.templates' => array( 'twig.templates' => array(
'hello' => '{{ render("/foo") }}', 'hello' => '{{ render("/foo") }}',
......
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