123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
-
-
-
-
- class Twig_TokenParserBroker implements Twig_TokenParserBrokerInterface
- {
- protected $parser;
- protected $parsers = array();
- protected $brokers = array();
-
-
-
- public function __construct($parsers = array(), $brokers = array())
- {
- foreach ($parsers as $parser) {
- if (!$parser instanceof Twig_TokenParserInterface) {
- throw new Twig_Error('$parsers must a an array of Twig_TokenParserInterface');
- }
- $this->parsers[$parser->getTag()] = $parser;
- }
- foreach ($brokers as $broker) {
- if (!$broker instanceof Twig_TokenParserBrokerInterface) {
- throw new Twig_Error('$brokers must a an array of Twig_TokenParserBrokerInterface');
- }
- $this->brokers[] = $broker;
- }
- }
-
-
-
- public function addTokenParser(Twig_TokenParserInterface $parser)
- {
- $this->parsers[$parser->getTag()] = $parser;
- }
-
-
-
- public function addTokenParserBroker(Twig_TokenParserBroker $broker)
- {
- $this->brokers[] = $broker;
- }
-
-
-
- public function getTokenParser($tag)
- {
- if (isset($this->parsers[$tag])) {
- return $this->parsers[$tag];
- }
- $broker = end($this->brokers);
- while (false !== $broker) {
- $parser = $broker->getTokenParser($tag);
- if (null !== $parser) {
- return $parser;
- }
- $broker = prev($this->brokers);
- }
- return null;
- }
-
- public function getParsers()
- {
- return $this->parsers;
- }
-
- public function getParser()
- {
- return $this->parser;
- }
-
- public function setParser(Twig_ParserInterface $parser)
- {
- $this->parser = $parser;
- foreach ($this->parsers as $tokenParser) {
- $tokenParser->setParser($parser);
- }
- foreach ($this->brokers as $broker) {
- $broker->setParser($parser);
- }
- }
- }
|