added a way to add token parsers, filters, and visitors without creating an extension
authorFabien Potencier <fabien.potencier@gmail.com>
Wed, 26 May 2010 09:28:06 +0000 (11:28 +0200)
committerFabien Potencier <fabien.potencier@gmail.com>
Wed, 26 May 2010 09:28:06 +0000 (11:28 +0200)
CHANGELOG
lib/Twig/Environment.php

index 00f4346..39cd653 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -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 }})
index d7acfd7..eb69278 100644 (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) {