aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/Twig/Extensions/Grammar/Tag.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2013-08-02 22:40:51 +0200
committerNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2013-08-02 22:40:51 +0200
commita4565e88edbc8e3bd092a475469769c86a4c350c (patch)
treea6a3c935b03a23ff87575c8c315cf8ba78fe68c2 /inc/Twig/Extensions/Grammar/Tag.php
parentf6c9baab3efeec1d0efa151e276fc08d5b58f9e9 (diff)
downloadwallabag-a4565e88edbc8e3bd092a475469769c86a4c350c.tar.gz
wallabag-a4565e88edbc8e3bd092a475469769c86a4c350c.tar.zst
wallabag-a4565e88edbc8e3bd092a475469769c86a4c350c.zip
add Twig & refactor poche
Diffstat (limited to 'inc/Twig/Extensions/Grammar/Tag.php')
-rw-r--r--inc/Twig/Extensions/Grammar/Tag.php56
1 files changed, 56 insertions, 0 deletions
diff --git a/inc/Twig/Extensions/Grammar/Tag.php b/inc/Twig/Extensions/Grammar/Tag.php
new file mode 100644
index 00000000..727f2610
--- /dev/null
+++ b/inc/Twig/Extensions/Grammar/Tag.php
@@ -0,0 +1,56 @@
1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) 2010 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 */
11class Twig_Extensions_Grammar_Tag extends Twig_Extensions_Grammar
12{
13 protected $grammar;
14
15 public function __construct()
16 {
17 $this->grammar = array();
18 foreach (func_get_args() as $grammar) {
19 $this->addGrammar($grammar);
20 }
21 }
22
23 public function __toString()
24 {
25 $repr = array();
26 foreach ($this->grammar as $grammar) {
27 $repr[] = (string) $grammar;
28 }
29
30 return implode(' ', $repr);
31 }
32
33 public function addGrammar(Twig_Extensions_GrammarInterface $grammar)
34 {
35 $this->grammar[] = $grammar;
36 }
37
38 public function parse(Twig_Token $token)
39 {
40 $elements = array();
41 foreach ($this->grammar as $grammar) {
42 $grammar->setParser($this->parser);
43
44 $element = $grammar->parse($token);
45 if (is_array($element)) {
46 $elements = array_merge($elements, $element);
47 } else {
48 $elements[$grammar->getName()] = $element;
49 }
50 }
51
52 $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
53
54 return $elements;
55 }
56}