ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
TokenParserBroker.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) Fabien Potencier
7 * (c) 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
21{
22 protected $parser;
23 protected $parsers = array();
24 protected $brokers = array();
25
31 public function __construct($parsers = array(), $brokers = array(), $triggerDeprecationError = true)
32 {
33 if ($triggerDeprecationError) {
34 @trigger_error('The '.__CLASS__.' class is deprecated since version 1.12 and will be removed in 2.0.', E_USER_DEPRECATED);
35 }
36
37 foreach ($parsers as $parser) {
38 if (!$parser instanceof Twig_TokenParserInterface) {
39 throw new LogicException('$parsers must a an array of Twig_TokenParserInterface.');
40 }
41 $this->parsers[$parser->getTag()] = $parser;
42 }
43 foreach ($brokers as $broker) {
44 if (!$broker instanceof Twig_TokenParserBrokerInterface) {
45 throw new LogicException('$brokers must a an array of Twig_TokenParserBrokerInterface.');
46 }
47 $this->brokers[] = $broker;
48 }
49 }
50
52 {
53 $this->parsers[$parser->getTag()] = $parser;
54 }
55
57 {
58 $name = $parser->getTag();
59 if (isset($this->parsers[$name]) && $parser === $this->parsers[$name]) {
60 unset($this->parsers[$name]);
61 }
62 }
63
64 public function addTokenParserBroker(self $broker)
65 {
66 $this->brokers[] = $broker;
67 }
68
69 public function removeTokenParserBroker(self $broker)
70 {
71 if (false !== $pos = array_search($broker, $this->brokers)) {
72 unset($this->brokers[$pos]);
73 }
74 }
75
85 public function getTokenParser($tag)
86 {
87 if (isset($this->parsers[$tag])) {
88 return $this->parsers[$tag];
89 }
90 $broker = end($this->brokers);
91 while (false !== $broker) {
92 $parser = $broker->getTokenParser($tag);
93 if (null !== $parser) {
94 return $parser;
95 }
96 $broker = prev($this->brokers);
97 }
98 }
99
100 public function getParsers()
101 {
102 return $this->parsers;
103 }
104
105 public function getParser()
106 {
107 return $this->parser;
108 }
109
111 {
112 $this->parser = $parser;
113 foreach ($this->parsers as $tokenParser) {
114 $tokenParser->setParser($parser);
115 }
116 foreach ($this->brokers as $broker) {
117 $broker->setParser($parser);
118 }
119 }
120}
An exception for terminatinating execution or to throw for unit testing.
Default implementation of a token parser broker.
getParser()
Gets the Twig_ParserInterface.
getTokenParser($tag)
Gets a suitable TokenParser for a tag.
__construct($parsers=array(), $brokers=array(), $triggerDeprecationError=true)
removeTokenParserBroker(self $broker)
setParser(Twig_ParserInterface $parser)
Calls Twig_TokenParserInterface::setParser on all parsers the implementation knows of.
removeTokenParser(Twig_TokenParserInterface $parser)
addTokenParser(Twig_TokenParserInterface $parser)
addTokenParserBroker(self $broker)
Interface implemented by parser classes.
Interface implemented by token parser brokers.
Interface implemented by token parsers.
if(function_exists( 'posix_getuid') &&posix_getuid()===0) if(!array_key_exists('t', $options)) $tag
Definition: cron.php:35