1<?php 2 3/* 4 * This file is part of Twig. 5 * 6 * (c) 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 12namespace Twig\TokenParser; 13 14use Twig\Node\SpacelessNode; 15use Twig\Token; 16 17/** 18 * Remove whitespaces between HTML tags. 19 * 20 * {% spaceless %} 21 * <div> 22 * <strong>foo</strong> 23 * </div> 24 * {% endspaceless %} 25 * {# output will be <div><strong>foo</strong></div> #} 26 * 27 * @deprecated since Twig 2.7, to be removed in 3.0 (use the "spaceless" filter with the "apply" tag instead) 28 */ 29final class SpacelessTokenParser extends AbstractTokenParser 30{ 31 public function parse(Token $token) 32 { 33 $stream = $this->parser->getStream(); 34 $lineno = $token->getLine(); 35 36 @trigger_error(sprintf('The spaceless tag in "%s" at line %d is deprecated since Twig 2.7, use the "spaceless" filter with the "apply" tag instead.', $stream->getSourceContext()->getName(), $lineno), \E_USER_DEPRECATED); 37 38 $stream->expect(/* Token::BLOCK_END_TYPE */ 3); 39 $body = $this->parser->subparse([$this, 'decideSpacelessEnd'], true); 40 $stream->expect(/* Token::BLOCK_END_TYPE */ 3); 41 42 return new SpacelessNode($body, $lineno, $this->getTag()); 43 } 44 45 public function decideSpacelessEnd(Token $token) 46 { 47 return $token->test('endspaceless'); 48 } 49 50 public function getTag() 51 { 52 return 'spaceless'; 53 } 54} 55 56class_alias('Twig\TokenParser\SpacelessTokenParser', 'Twig_TokenParser_Spaceless'); 57