1<?php 2 3/* 4 * This file is part of Twig. 5 * 6 * (c) Fabien Potencier 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace Twig\Extension; 13 14use Twig\NodeVisitor\NodeVisitorInterface; 15use Twig\TokenParser\TokenParserInterface; 16use Twig\TwigFilter; 17use Twig\TwigFunction; 18use Twig\TwigTest; 19 20/** 21 * Used by \Twig\Environment as a staging area. 22 * 23 * @author Fabien Potencier <fabien@symfony.com> 24 * 25 * @internal 26 */ 27final class StagingExtension extends AbstractExtension 28{ 29 private $functions = []; 30 private $filters = []; 31 private $visitors = []; 32 private $tokenParsers = []; 33 private $tests = []; 34 35 public function addFunction(TwigFunction $function) 36 { 37 if (isset($this->functions[$function->getName()])) { 38 throw new \LogicException(sprintf('Function "%s" is already registered.', $function->getName())); 39 } 40 41 $this->functions[$function->getName()] = $function; 42 } 43 44 public function getFunctions() 45 { 46 return $this->functions; 47 } 48 49 public function addFilter(TwigFilter $filter) 50 { 51 if (isset($this->filters[$filter->getName()])) { 52 throw new \LogicException(sprintf('Filter "%s" is already registered.', $filter->getName())); 53 } 54 55 $this->filters[$filter->getName()] = $filter; 56 } 57 58 public function getFilters() 59 { 60 return $this->filters; 61 } 62 63 public function addNodeVisitor(NodeVisitorInterface $visitor) 64 { 65 $this->visitors[] = $visitor; 66 } 67 68 public function getNodeVisitors() 69 { 70 return $this->visitors; 71 } 72 73 public function addTokenParser(TokenParserInterface $parser) 74 { 75 if (isset($this->tokenParsers[$parser->getTag()])) { 76 throw new \LogicException(sprintf('Tag "%s" is already registered.', $parser->getTag())); 77 } 78 79 $this->tokenParsers[$parser->getTag()] = $parser; 80 } 81 82 public function getTokenParsers() 83 { 84 return $this->tokenParsers; 85 } 86 87 public function addTest(TwigTest $test) 88 { 89 if (isset($this->tests[$test->getName()])) { 90 throw new \LogicException(sprintf('Test "%s" is already registered.', $test->getName())); 91 } 92 93 $this->tests[$test->getName()] = $test; 94 } 95 96 public function getTests() 97 { 98 return $this->tests; 99 } 100} 101 102class_alias('Twig\Extension\StagingExtension', 'Twig_Extension_Staging'); 103