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 */ 11 12/** 13 * @deprecated since version 1.5 14 */ 15class Twig_Extensions_Grammar_Tag extends Twig_Extensions_Grammar 16{ 17 protected $grammar; 18 19 public function __construct() 20 { 21 $this->grammar = array(); 22 foreach (func_get_args() as $grammar) { 23 $this->addGrammar($grammar); 24 } 25 } 26 27 public function __toString() 28 { 29 $repr = array(); 30 foreach ($this->grammar as $grammar) { 31 $repr[] = (string) $grammar; 32 } 33 34 return implode(' ', $repr); 35 } 36 37 public function addGrammar(Twig_Extensions_GrammarInterface $grammar) 38 { 39 $this->grammar[] = $grammar; 40 } 41 42 public function parse(Twig_Token $token) 43 { 44 $elements = array(); 45 foreach ($this->grammar as $grammar) { 46 $grammar->setParser($this->parser); 47 48 $element = $grammar->parse($token); 49 if (is_array($element)) { 50 $elements = array_merge($elements, $element); 51 } else { 52 $elements[$grammar->getName()] = $element; 53 } 54 } 55 56 $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); 57 58 return $elements; 59 } 60} 61