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) {
public function addFilter($name, Twig_FilterInterface $filter)
{
if (null === $this->filters) {
- $this->loadFilters();
+ $this->getFilters();
}
$this->filters[$name] = $filter;
public function getFilter($name)
{
if (null === $this->filters) {
- $this->loadFilters();
+ $this->getFilters();
}
if (isset($this->filters[$name])) {
*
* @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;
}
/**
public function addFunction($name, Twig_FunctionInterface $function)
{
if (null === $this->functions) {
- $this->loadFunctions();
+ $this->getFunctions();
}
$this->functions[$name] = $function;
public function getFunction($name)
{
if (null === $this->functions) {
- $this->loadFunctions();
+ $this->getFunctions();
}
if (isset($this->functions[$name])) {
$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;
}
/**