From 4018040bbb9557e9ce2cbf72b56f0f14730f7532 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Tue, 24 May 2011 09:08:42 -0700 Subject: [PATCH] [TwigBundle] reverted to lazy-loading of templating helpers (fixes #1066) --- .../TwigBundle/Extension/ActionsExtension.php | 17 ++++++------- .../TwigBundle/Extension/AssetsExtension.php | 15 +++++------- .../TwigBundle/Extension/CodeExtension.php | 24 +++++++++---------- .../TwigBundle/Resources/config/twig.xml | 6 ++--- 4 files changed, 28 insertions(+), 34 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/Extension/ActionsExtension.php b/src/Symfony/Bundle/TwigBundle/Extension/ActionsExtension.php index 519e783062..017bfb4311 100644 --- a/src/Symfony/Bundle/TwigBundle/Extension/ActionsExtension.php +++ b/src/Symfony/Bundle/TwigBundle/Extension/ActionsExtension.php @@ -12,7 +12,7 @@ namespace Symfony\Bundle\TwigBundle\Extension; use Symfony\Bundle\TwigBundle\TokenParser\RenderTokenParser; -use Symfony\Bundle\FrameworkBundle\Templating\Helper\ActionsHelper; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Twig extension for Symfony actions helper @@ -21,19 +21,16 @@ use Symfony\Bundle\FrameworkBundle\Templating\Helper\ActionsHelper; */ class ActionsExtension extends \Twig_Extension { - /** - * @var Symfony\Bundle\FrameworkBundle\Templating\Helper\ActionsHelper - */ - private $helper; + private $container; /** - * Construct the extension with a HTTP Kernel + * Constructor. * - * @param HttpKernel $kernel The kernel to use for sub-requests + * @param ContainerInterface $container The service container */ - public function __construct(ActionsHelper $helper) + public function __construct(ContainerInterface $container) { - $this->helper = $helper; + $this->container = $container; } /** @@ -47,7 +44,7 @@ class ActionsExtension extends \Twig_Extension */ public function renderAction($controller, array $attributes = array(), array $options = array()) { - return $this->helper->render($controller, $attributes, $options); + return $this->container->get('templating.helper.actions')->render($controller, $attributes, $options); } /** diff --git a/src/Symfony/Bundle/TwigBundle/Extension/AssetsExtension.php b/src/Symfony/Bundle/TwigBundle/Extension/AssetsExtension.php index 2fb9ed0f71..8581ebcb56 100644 --- a/src/Symfony/Bundle/TwigBundle/Extension/AssetsExtension.php +++ b/src/Symfony/Bundle/TwigBundle/Extension/AssetsExtension.php @@ -11,21 +11,18 @@ namespace Symfony\Bundle\TwigBundle\Extension; -use Symfony\Bundle\FrameworkBundle\Templating\Helper\AssetsHelper; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * @author Fabien Potencier */ class AssetsExtension extends \Twig_Extension { - /** - * @var Symfony\Bundle\FrameworkBundle\Templating\Helper\AssetsHelper - */ - private $helper; + private $container; - public function __construct(AssetsHelper $helper) + public function __construct(ContainerInterface $container) { - $this->helper = $helper; + $this->container = $container; } /** @@ -53,7 +50,7 @@ class AssetsExtension extends \Twig_Extension */ public function getAssetUrl($path, $packageName = null) { - return $this->helper->getUrl($path, $packageName); + return $this->container->get('templating.helper.assets')->getUrl($path, $packageName); } /** @@ -64,7 +61,7 @@ class AssetsExtension extends \Twig_Extension */ public function getAssetsVersion($packageName = null) { - return $this->helper->getVersion($packageName); + return $this->container->get('templating.helper.assets')->getVersion($packageName); } /** diff --git a/src/Symfony/Bundle/TwigBundle/Extension/CodeExtension.php b/src/Symfony/Bundle/TwigBundle/Extension/CodeExtension.php index 144dde19a7..44e82e4ccc 100644 --- a/src/Symfony/Bundle/TwigBundle/Extension/CodeExtension.php +++ b/src/Symfony/Bundle/TwigBundle/Extension/CodeExtension.php @@ -11,7 +11,7 @@ namespace Symfony\Bundle\TwigBundle\Extension; -use Symfony\Bundle\FrameworkBundle\Templating\Helper\CodeHelper; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * @@ -19,16 +19,16 @@ use Symfony\Bundle\FrameworkBundle\Templating\Helper\CodeHelper; */ class CodeExtension extends \Twig_Extension { - private $helper; + private $container; /** * Constructor of Twig Extension to provide functions for code formatting * * @param Symfony\Bundle\FrameworkBundle\Templating\Helper\CodeHelper $helper Helper to use */ - public function __construct(CodeHelper $helper) + public function __construct(ContainerInterface $container) { - $this->helper = $helper; + $this->container = $container; } /** @@ -50,42 +50,42 @@ class CodeExtension extends \Twig_Extension public function abbrClass($class) { - return $this->helper->abbrClass($class); + return $this->container->get('templating.helper.code')->abbrClass($class); } public function abbrMethod($method) { - return $this->helper->abbrMethod($method); + return $this->container->get('templating.helper.code')->abbrMethod($method); } public function formatArgs($args) { - return $this->helper->formatArgs($args); + return $this->container->get('templating.helper.code')->formatArgs($args); } public function formatArgsAsText($args) { - return $this->helper->formatArgsAsText($args); + return $this->container->get('templating.helper.code')->formatArgsAsText($args); } public function fileExcerpt($file, $line) { - return $this->helper->fileExcerpt($file, $line); + return $this->container->get('templating.helper.code')->fileExcerpt($file, $line); } public function formatFile($file, $line, $text = null) { - return $this->helper->formatFile($file, $line, $text); + return $this->container->get('templating.helper.code')->formatFile($file, $line, $text); } public function getFileLink($file, $line) { - return $this->helper->getFileLink($file, $line); + return $this->container->get('templating.helper.code')->getFileLink($file, $line); } public function formatFileFromText($text) { - return $this->helper->formatFileFromText($text); + return $this->container->get('templating.helper.code')->formatFileFromText($text); } public function getName() diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml index ee4d2ae866..8bceda5135 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml @@ -49,17 +49,17 @@ - + - + - +