PEEL Shopping
Open source ecommerce : PEEL Shopping
AutoEscape.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of Twig.
5  *
6  * (c) 2009 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 
31 {
39  public function parse(Twig_Token $token)
40  {
41  $lineno = $token->getLine();
42  $stream = $this->parser->getStream();
43 
44  if ($stream->test(Twig_Token::BLOCK_END_TYPE)) {
45  $value = 'html';
46  } else {
47  $expr = $this->parser->getExpressionParser()->parseExpression();
48  if (!$expr instanceof Twig_Node_Expression_Constant) {
49  throw new Twig_Error_Syntax('An escaping strategy must be a string or a Boolean.', $stream->getCurrent()->getLine(), $stream->getFilename());
50  }
51  $value = $expr->getAttribute('value');
52 
53  $compat = true === $value || false === $value;
54 
55  if (true === $value) {
56  $value = 'html';
57  }
58 
59  if ($compat && $stream->test(Twig_Token::NAME_TYPE)) {
60  if (false === $value) {
61  throw new Twig_Error_Syntax('Unexpected escaping strategy as you set autoescaping to false.', $stream->getCurrent()->getLine(), $stream->getFilename());
62  }
63 
64  $value = $stream->next()->getValue();
65  }
66  }
67 
68  $stream->expect(Twig_Token::BLOCK_END_TYPE);
69  $body = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
70  $stream->expect(Twig_Token::BLOCK_END_TYPE);
71 
72  return new Twig_Node_AutoEscape($value, $body, $lineno, $this->getTag());
73  }
74 
75  public function decideBlockEnd(Twig_Token $token)
76  {
77  return $token->test('endautoescape');
78  }
79 
85  public function getTag()
86  {
87  return 'autoescape';
88  }
89 }
Base class for all token parsers.
Definition: TokenParser.php:17
decideBlockEnd(Twig_Token $token)
Definition: AutoEscape.php:75
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:18
Marks a section of a template to be escaped or not.
Definition: AutoEscape.php:30
Represents an autoescape node.
Definition: AutoEscape.php:23
getTag()
Gets the tag name associated with this token parser.
Definition: AutoEscape.php:85
const BLOCK_END_TYPE
Definition: Token.php:28
Represents a Token.
Definition: Token.php:18
const NAME_TYPE
Definition: Token.php:30
getLine()
Gets the line.
Definition: Token.php:94
test($type, $values=null)
Tests the current token for a type and/or a value.
Definition: Token.php:75
parse(Twig_Token $token)
Parses a token and returns a node.
Definition: AutoEscape.php:39

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:41:18 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.