From 2f67776a66c2cdf8505696bfa225e95396da1b57 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 11 Aug 2013 20:24:06 +0200 Subject: [PATCH] removed unneeded safeguard as it's already done during compilation --- .../Twig/Extension/StopwatchExtension.php | 19 +++++-------------- .../Bridge/Twig/Node/StopwatchNode.php | 8 +++----- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Extension/StopwatchExtension.php b/src/Symfony/Bridge/Twig/Extension/StopwatchExtension.php index 6379f1a73d..1055b5bac8 100644 --- a/src/Symfony/Bridge/Twig/Extension/StopwatchExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/StopwatchExtension.php @@ -28,6 +28,11 @@ class StopwatchExtension extends \Twig_Extension $this->stopwatch = $stopwatch; } + public function getStopwatch() + { + return $this->stopwatch; + } + public function getTokenParsers() { return array( @@ -44,18 +49,4 @@ class StopwatchExtension extends \Twig_Extension { return 'stopwatch'; } - - public function startEvent($name) - { - if ($this->stopwatch instanceof Stopwatch) { - $this->stopwatch->start($name, 'template'); - } - } - - public function stopEvent($name) - { - if ($this->stopwatch instanceof Stopwatch) { - $this->stopwatch->stop($name); - } - } } diff --git a/src/Symfony/Bridge/Twig/Node/StopwatchNode.php b/src/Symfony/Bridge/Twig/Node/StopwatchNode.php index e38fd4e6e9..eac3fce9a4 100644 --- a/src/Symfony/Bridge/Twig/Node/StopwatchNode.php +++ b/src/Symfony/Bridge/Twig/Node/StopwatchNode.php @@ -25,12 +25,10 @@ class StopwatchNode extends \Twig_Node public function compile(\Twig_Compiler $compiler) { - $name = $this->getAttribute('name'); - $compiler - ->write('$this->env->getExtension(\'stopwatch\')->startEvent(\''.$name.'\');') + ->write(sprintf("\$this->env->getExtension('stopwatch')->getStopwatch()->start('%s', 'template');\n", $this->getAttribute('name'))) ->subcompile($this->getNode('body')) - ->write('$this->env->getExtension(\'stopwatch\')->stopEvent(\''.$name.'\');') - ->raw("\n"); + ->write(sprintf("\$this->env->getExtension('stopwatch')->getStopwatch()->stop('%s');\n", $this->getAttribute('name'))) + ; } }