From: Fabien Potencier Date: Wed, 26 May 2010 09:28:06 +0000 (+0200) Subject: added a way to add token parsers, filters, and visitors without creating an extension X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=255f0fb80d8492e0280138c5a73bf7d1381f5800;p=web%2Fkonrad%2Ftwig.git added a way to add token parsers, filters, and visitors without creating an extension --- diff --git a/CHANGELOG b/CHANGELOG index 00f4346..39cd653 100644 --- 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 }}) diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index d7acfd7..eb69278 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -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) {