added a way to add token parsers, filters, and visitors without creating an extension

This commit is contained in:
Fabien Potencier
2010-05-26 11:28:06 +02:00
parent c4e80ee525
commit 255f0fb80d
2 changed files with 28 additions and 0 deletions
+1
View File
@@ -3,6 +3,7 @@
Backward incompatibilities:
* The short notation of the `block` tag changed.
* added a way to add token parsers, filters, and visitors without creating an extension
* added three interfaces: Twig_NodeInterface, Twig_TokenParserInterface, and Twig_FilterInterface
* changed the generated code to match the new coding standards
* fixed sandbox mode (__toString() method check was not enforced if called implicitly from a simple statement like {{ article }})
+27
View File
@@ -323,6 +323,15 @@ class Twig_Environment
return $this->extensions;
}
public function addTokenParser(Twig_TokenParserInterface $parser)
{
if (null === $this->parsers) {
$this->getTokenParsers();
}
$this->parsers[] = $parser;
}
public function getTokenParsers()
{
if (null === $this->parsers) {
@@ -335,6 +344,15 @@ class Twig_Environment
return $this->parsers;
}
public function addNodeVisitor(Twig_NodeVisitorInterface $visitor)
{
if (null === $this->visitors) {
$this->getNodeVisitors();
}
$this->visitors[] = $visitor;
}
public function getNodeVisitors()
{
if (null === $this->visitors) {
@@ -347,6 +365,15 @@ class Twig_Environment
return $this->visitors;
}
public function addFilter($name, Twig_NodeFilter $filter)
{
if (null === $this->filters) {
$this->getFilters();
}
$this->filters[$name] = $filter;
}
public function getFilters()
{
if (null === $this->filters) {