diff options
author | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-02 22:43:56 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-02 22:43:56 +0200 |
commit | 8069e235fd2971675ee5fc05026ffa9bce5cbbb7 (patch) | |
tree | 872eaed228b5e1b031c21770fba1701106a52a39 /inc/3rdparty/Twig/TokenParserBroker.php | |
parent | 45161a64026cec35fcf07659508143a6f55ddf57 (diff) | |
download | wallabag-8069e235fd2971675ee5fc05026ffa9bce5cbbb7.tar.gz wallabag-8069e235fd2971675ee5fc05026ffa9bce5cbbb7.tar.zst wallabag-8069e235fd2971675ee5fc05026ffa9bce5cbbb7.zip |
move Twig in 3rdparty
Diffstat (limited to 'inc/3rdparty/Twig/TokenParserBroker.php')
-rw-r--r-- | inc/3rdparty/Twig/TokenParserBroker.php | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/inc/3rdparty/Twig/TokenParserBroker.php b/inc/3rdparty/Twig/TokenParserBroker.php new file mode 100644 index 00000000..ec3fba67 --- /dev/null +++ b/inc/3rdparty/Twig/TokenParserBroker.php | |||
@@ -0,0 +1,136 @@ | |||
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 | |||
13 | /** | ||
14 | * Default implementation of a token parser broker. | ||
15 | * | ||
16 | * @author Arnaud Le Blanc <arnaud.lb@gmail.com> | ||
17 | * @deprecated since 1.12 (to be removed in 2.0) | ||
18 | */ | ||
19 | class Twig_TokenParserBroker implements Twig_TokenParserBrokerInterface | ||
20 | { | ||
21 | protected $parser; | ||
22 | protected $parsers = array(); | ||
23 | protected $brokers = array(); | ||
24 | |||
25 | /** | ||
26 | * Constructor. | ||
27 | * | ||
28 | * @param array|Traversable $parsers A Traversable of Twig_TokenParserInterface instances | ||
29 | * @param array|Traversable $brokers A Traversable of Twig_TokenParserBrokerInterface instances | ||
30 | */ | ||
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 | |||
47 | /** | ||
48 | * Adds a TokenParser. | ||
49 | * | ||
50 | * @param Twig_TokenParserInterface $parser A Twig_TokenParserInterface instance | ||
51 | */ | ||
52 | public function addTokenParser(Twig_TokenParserInterface $parser) | ||
53 | { | ||
54 | $this->parsers[$parser->getTag()] = $parser; | ||
55 | } | ||
56 | |||
57 | /** | ||
58 | * Removes a TokenParser. | ||
59 | * | ||
60 | * @param Twig_TokenParserInterface $parser A Twig_TokenParserInterface instance | ||
61 | */ | ||
62 | public function removeTokenParser(Twig_TokenParserInterface $parser) | ||
63 | { | ||
64 | $name = $parser->getTag(); | ||
65 | if (isset($this->parsers[$name]) && $parser === $this->parsers[$name]) { | ||
66 | unset($this->parsers[$name]); | ||
67 | } | ||
68 | } | ||
69 | |||
70 | /** | ||
71 | * Adds a TokenParserBroker. | ||
72 | * | ||
73 | * @param Twig_TokenParserBroker $broker A Twig_TokenParserBroker instance | ||
74 | */ | ||
75 | public function addTokenParserBroker(Twig_TokenParserBroker $broker) | ||
76 | { | ||
77 | $this->brokers[] = $broker; | ||
78 | } | ||
79 | |||
80 | /** | ||
81 | * Removes a TokenParserBroker. | ||
82 | * | ||
83 | * @param Twig_TokenParserBroker $broker A Twig_TokenParserBroker instance | ||
84 | */ | ||
85 | public function removeTokenParserBroker(Twig_TokenParserBroker $broker) | ||
86 | { | ||
87 | if (false !== $pos = array_search($broker, $this->brokers)) { | ||
88 | unset($this->brokers[$pos]); | ||
89 | } | ||
90 | } | ||
91 | |||
92 | /** | ||
93 | * Gets a suitable TokenParser for a tag. | ||
94 | * | ||
95 | * First looks in parsers, then in brokers. | ||
96 | * | ||
97 | * @param string $tag A tag name | ||
98 | * | ||
99 | * @return null|Twig_TokenParserInterface A Twig_TokenParserInterface or null if no suitable TokenParser was found | ||
100 | */ | ||
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 | |||
126 | public function setParser(Twig_ParserInterface $parser) | ||
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 | } | ||