removed unneeded safeguard as it's already done during compilation
This commit is contained in:
parent
bbad387e4b
commit
2f67776a66
@ -28,6 +28,11 @@ class StopwatchExtension extends \Twig_Extension
|
|||||||
$this->stopwatch = $stopwatch;
|
$this->stopwatch = $stopwatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getStopwatch()
|
||||||
|
{
|
||||||
|
return $this->stopwatch;
|
||||||
|
}
|
||||||
|
|
||||||
public function getTokenParsers()
|
public function getTokenParsers()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
@ -44,18 +49,4 @@ class StopwatchExtension extends \Twig_Extension
|
|||||||
{
|
{
|
||||||
return 'stopwatch';
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -25,12 +25,10 @@ class StopwatchNode extends \Twig_Node
|
|||||||
|
|
||||||
public function compile(\Twig_Compiler $compiler)
|
public function compile(\Twig_Compiler $compiler)
|
||||||
{
|
{
|
||||||
$name = $this->getAttribute('name');
|
|
||||||
|
|
||||||
$compiler
|
$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'))
|
->subcompile($this->getNode('body'))
|
||||||
->write('$this->env->getExtension(\'stopwatch\')->stopEvent(\''.$name.'\');')
|
->write(sprintf("\$this->env->getExtension('stopwatch')->getStopwatch()->stop('%s');\n", $this->getAttribute('name')))
|
||||||
->raw("\n");
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user