From: Fabien Potencier Date: Sat, 15 Oct 2011 08:57:18 +0000 (+0200) Subject: added public getters on the environment to be able to get various stuff X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=ac3bb814d59afbe4f713c2ffdfb95dffa12c83d7;p=web%2Fkonrad%2Ftwig.git added public getters on the environment to be able to get various stuff --- diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index 902b6fa..27fd62f 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -661,7 +661,7 @@ class Twig_Environment public function getTokenParsers() { if (null === $this->parsers) { - $this->parsers = new Twig_TokenParserBroker; + $this->parsers = new Twig_TokenParserBroker(); foreach ($this->getExtensions() as $extension) { $parsers = $extension->getTokenParsers(); foreach($parsers as $parser) { @@ -719,7 +719,7 @@ class Twig_Environment public function addFilter($name, Twig_FilterInterface $filter) { if (null === $this->filters) { - $this->loadFilters(); + $this->getFilters(); } $this->filters[$name] = $filter; @@ -738,7 +738,7 @@ class Twig_Environment public function getFilter($name) { if (null === $this->filters) { - $this->loadFilters(); + $this->getFilters(); } if (isset($this->filters[$name])) { @@ -764,12 +764,16 @@ class Twig_Environment * * @return Twig_FilterInterface[] An array of Twig_FilterInterface instances */ - protected function loadFilters() + public function getFilters() { - $this->filters = array(); - foreach ($this->getExtensions() as $extension) { - $this->filters = array_merge($this->filters, $extension->getFilters()); + if (null === $this->filters) { + $this->filters = array(); + foreach ($this->getExtensions() as $extension) { + $this->filters = array_merge($this->filters, $extension->getFilters()); + } } + + return $this->filters; } /** @@ -813,7 +817,7 @@ class Twig_Environment public function addFunction($name, Twig_FunctionInterface $function) { if (null === $this->functions) { - $this->loadFunctions(); + $this->getFunctions(); } $this->functions[$name] = $function; @@ -832,7 +836,7 @@ class Twig_Environment public function getFunction($name) { if (null === $this->functions) { - $this->loadFunctions(); + $this->getFunctions(); } if (isset($this->functions[$name])) { @@ -853,12 +857,16 @@ class Twig_Environment $this->functionCallbacks[] = $callable; } - protected function loadFunctions() + public function getFunctions() { - $this->functions = array(); - foreach ($this->getExtensions() as $extension) { - $this->functions = array_merge($this->functions, $extension->getFunctions()); + if (null === $this->functions) { + $this->functions = array(); + foreach ($this->getExtensions() as $extension) { + $this->functions = array_merge($this->functions, $extension->getFunctions()); + } } + + return $this->functions; } /** diff --git a/lib/Twig/TokenParserBroker.php b/lib/Twig/TokenParserBroker.php index 34fcdfb..4b2ff41 100644 --- a/lib/Twig/TokenParserBroker.php +++ b/lib/Twig/TokenParserBroker.php @@ -89,6 +89,11 @@ class Twig_TokenParserBroker implements Twig_TokenParserBrokerInterface return null; } + public function getParsers() + { + return $this->parsers; + } + public function getParser() { return $this->parser;