protected $templateClassPrefix = '__TwigTemplate_';
protected $functionCallbacks;
protected $filterCallbacks;
+ protected $staging;
/**
* Constructor.
*/
public function addTokenParser(Twig_TokenParserInterface $parser)
{
- if (null === $this->parsers) {
- $this->getTokenParsers();
- }
-
- $this->parsers->addTokenParser($parser);
+ $this->stating['token_parsers'][] = $parser;
}
/**
{
if (null === $this->parsers) {
$this->parsers = new Twig_TokenParserBroker();
+
+ if (isset($this->stating['token_parsers'])) {
+ foreach ($this->stating['token_parsers'] as $parser) {
+ $this->parsers->addTokenParser($parser);
+ }
+ }
+
foreach ($this->getExtensions() as $extension) {
$parsers = $extension->getTokenParsers();
foreach($parsers as $parser) {
*/
public function addNodeVisitor(Twig_NodeVisitorInterface $visitor)
{
- if (null === $this->visitors) {
- $this->getNodeVisitors();
- }
-
- $this->visitors[] = $visitor;
+ $this->stating['visitors'][] = $visitor;
}
/**
public function getNodeVisitors()
{
if (null === $this->visitors) {
- $this->visitors = array();
+ $this->visitors = isset($this->stating['visitors']) ? $this->stating['visitors'] : array();
foreach ($this->getExtensions() as $extension) {
$this->visitors = array_merge($this->visitors, $extension->getNodeVisitors());
}
*/
public function addFilter($name, Twig_FilterInterface $filter)
{
- if (null === $this->filters) {
- $this->getFilters();
- }
-
- $this->filters[$name] = $filter;
+ $this->staging['filters'][$name] = $filter;
}
/**
public function getFilters()
{
if (null === $this->filters) {
- $this->filters = array();
+ $this->filters = isset($this->staging['filters']) ? $this->staging['filters'] : array();
foreach ($this->getExtensions() as $extension) {
$this->filters = array_merge($this->filters, $extension->getFilters());
}
*/
public function addTest($name, Twig_TestInterface $test)
{
- if (null === $this->tests) {
- $this->getTests();
- }
-
- $this->tests[$name] = $test;
+ $this->staging['tests'][$name] = $test;
}
/**
public function getTests()
{
if (null === $this->tests) {
- $this->tests = array();
+ $this->tests = isset($this->staging['tests']) ? $this->staging['tests'] : array();
foreach ($this->getExtensions() as $extension) {
$this->tests = array_merge($this->tests, $extension->getTests());
}
*/
public function addFunction($name, Twig_FunctionInterface $function)
{
- if (null === $this->functions) {
- $this->getFunctions();
- }
-
- $this->functions[$name] = $function;
+ $this->staging['functions'][$name] = $function;
}
/**
public function getFunctions()
{
if (null === $this->functions) {
- $this->functions = array();
+ $this->functions = isset($this->staging['functions']) ? $this->staging['functions'] : array();
foreach ($this->getExtensions() as $extension) {
$this->functions = array_merge($this->functions, $extension->getFunctions());
}
*/
public function addGlobal($name, $value)
{
- if (null === $this->globals) {
- $this->getGlobals();
- }
-
- $this->globals[$name] = $value;
+ $this->staging['globals'][$name] = $value;
}
/**
public function getGlobals()
{
if (null === $this->globals) {
- $this->globals = array();
+ $this->globals = isset($this->staging['globals']) ? $this->staging['globals'] : array();
foreach ($this->getExtensions() as $extension) {
$this->globals = array_merge($this->globals, $extension->getGlobals());
}