removed unneeded safeguard as it's already done during compilation

This commit is contained in:
Fabien Potencier 2013-08-11 20:24:06 +02:00
parent bbad387e4b
commit 2f67776a66
2 changed files with 8 additions and 19 deletions

View File

@ -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);
}
}
}

View File

@ -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')))
;
}
}