From 29013a9f633924faaa5658f2e8541df7371bd7eb Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 17 Jan 2015 22:30:01 +0100 Subject: [PATCH] removed deprecated class --- doc/changelog.rst | 1 + src/Silex/Provider/TwigCoreExtension.php | 56 ------------------- src/Silex/Provider/TwigServiceProvider.php | 3 - .../Provider/TwigServiceProviderTest.php | 6 ++ 4 files changed, 7 insertions(+), 59 deletions(-) delete mode 100644 src/Silex/Provider/TwigCoreExtension.php diff --git a/doc/changelog.rst b/doc/changelog.rst index 4f21994cf..739f2b0d0 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -4,6 +4,7 @@ Changelog 1.3.0 (2015-XX-XX) ------------------ +* removed deprecated TwigCoreExtension class (register the new HttpFragmentServiceProvider instead) * bumped minimum version of PHP to 5.3.9 1.2.3 (2015-01-20) diff --git a/src/Silex/Provider/TwigCoreExtension.php b/src/Silex/Provider/TwigCoreExtension.php deleted file mode 100644 index 06e41a0cc..000000000 --- a/src/Silex/Provider/TwigCoreExtension.php +++ /dev/null @@ -1,56 +0,0 @@ - - * - * 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 - * - * @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'; - } -} diff --git a/src/Silex/Provider/TwigServiceProvider.php b/src/Silex/Provider/TwigServiceProvider.php index 81cd6bb2a..d3eb95715 100644 --- a/src/Silex/Provider/TwigServiceProvider.php +++ b/src/Silex/Provider/TwigServiceProvider.php @@ -68,9 +68,6 @@ public function register(Application $app) $app['fragment.renderer.hinclude']->setTemplating($twig); $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'])) { diff --git a/tests/Silex/Tests/Provider/TwigServiceProviderTest.php b/tests/Silex/Tests/Provider/TwigServiceProviderTest.php index 474869833..7ec2e9295 100644 --- a/tests/Silex/Tests/Provider/TwigServiceProviderTest.php +++ b/tests/Silex/Tests/Provider/TwigServiceProviderTest.php @@ -13,6 +13,7 @@ use Silex\Application; use Silex\Provider\TwigServiceProvider; +use Silex\Provider\HttpFragmentServiceProvider; use Symfony\Component\HttpFoundation\Request; /** @@ -41,8 +42,13 @@ public function testRegisterAndRender() public function testRenderFunction() { + if (!class_exists('Symfony\Component\HttpFoundation\RequestStack')) { + $this->markTestSkipped(); + } + $app = new Application(); + $app->register(new HttpFragmentServiceProvider()); $app->register(new TwigServiceProvider(), array( 'twig.templates' => array( 'hello' => '{{ render("/foo") }}',