PEEL Shopping
Open source ecommerce : PEEL Shopping
TokenParserBroker.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of Twig.
5  *
6  * (c) 2010 Fabien Potencier
7  * (c) 2010 Arnaud Le Blanc
8  *
9  * For the full copyright and license information, please view the LICENSE
10  * file that was distributed with this source code.
11  */
12 
20 {
21  protected $parser;
22  protected $parsers = array();
23  protected $brokers = array();
24 
31  public function __construct($parsers = array(), $brokers = array())
32  {
33  foreach ($parsers as $parser) {
34  if (!$parser instanceof Twig_TokenParserInterface) {
35  throw new LogicException('$parsers must a an array of Twig_TokenParserInterface');
36  }
37  $this->parsers[$parser->getTag()] = $parser;
38  }
39  foreach ($brokers as $broker) {
40  if (!$broker instanceof Twig_TokenParserBrokerInterface) {
41  throw new LogicException('$brokers must a an array of Twig_TokenParserBrokerInterface');
42  }
43  $this->brokers[] = $broker;
44  }
45  }
46 
53  {
54  $this->parsers[$parser->getTag()] = $parser;
55  }
56 
63  {
64  $name = $parser->getTag();
65  if (isset($this->parsers[$name]) && $parser === $this->parsers[$name]) {
66  unset($this->parsers[$name]);
67  }
68  }
69 
76  {
77  $this->brokers[] = $broker;
78  }
79 
86  {
87  if (false !== $pos = array_search($broker, $this->brokers)) {
88  unset($this->brokers[$pos]);
89  }
90  }
91 
101  public function getTokenParser($tag)
102  {
103  if (isset($this->parsers[$tag])) {
104  return $this->parsers[$tag];
105  }
106  $broker = end($this->brokers);
107  while (false !== $broker) {
108  $parser = $broker->getTokenParser($tag);
109  if (null !== $parser) {
110  return $parser;
111  }
112  $broker = prev($this->brokers);
113  }
114  }
115 
116  public function getParsers()
117  {
118  return $this->parsers;
119  }
120 
121  public function getParser()
122  {
123  return $this->parser;
124  }
125 
127  {
128  $this->parser = $parser;
129  foreach ($this->parsers as $tokenParser) {
130  $tokenParser->setParser($parser);
131  }
132  foreach ($this->brokers as $broker) {
133  $broker->setParser($parser);
134  }
135  }
136 }
addTokenParserBroker(Twig_TokenParserBroker $broker)
Adds a TokenParserBroker.
getTag()
Gets the tag name associated with this token parser.
Default implementation of a token parser broker.
setParser(Twig_ParserInterface $parser)
Calls Twig_TokenParserInterface::setParser on all parsers the implementation knows of...
getParser()
Gets the Twig_ParserInterface.
Interface implemented by token parsers.
getTokenParser($tag)
Gets a suitable TokenParser for a tag.
removeTokenParser(Twig_TokenParserInterface $parser)
Removes a TokenParser.
Interface implemented by token parser brokers.
removeTokenParserBroker(Twig_TokenParserBroker $broker)
Removes a TokenParserBroker.
__construct($parsers=array(), $brokers=array())
Constructor.
addTokenParser(Twig_TokenParserInterface $parser)
Adds a TokenParser.
Interface implemented by parser classes.

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:41:19 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.