]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/twig/twig/lib/Twig/TokenParser/Block.php
4 * This file is part of Twig.
6 * (c) 2009 Fabien Potencier
7 * (c) 2009 Armin Ronacher
9 * For the full copyright and license information, please view the LICENSE
10 * file that was distributed with this source code.
14 * Marks a section of a template as being reusable.
18 * <link rel="stylesheet" href="style.css" />
19 * <title>{% block title %}{% endblock %} - My Webpage</title>
23 class Twig_TokenParser_Block
extends Twig_TokenParser
26 * Parses a token and returns a node.
28 * @param Twig_Token $token A Twig_Token instance
30 * @return Twig_NodeInterface A Twig_NodeInterface instance
32 public function parse ( Twig_Token
$token )
34 $lineno = $token- > getLine ();
35 $stream = $this- > parser
-> getStream ();
36 $name = $stream- > expect ( Twig_Token
:: NAME_TYPE
)-> getValue ();
37 if ( $this- > parser
-> hasBlock ( $name )) {
38 throw new Twig_Error_Syntax ( sprintf ( "The block ' $name' has already been defined line %d" , $this- > parser
-> getBlock ( $name )-> getLine ()), $stream- > getCurrent ()-> getLine (), $stream- > getFilename ());
40 $this- > parser
-> setBlock ( $name , $block = new Twig_Node_Block ( $name , new Twig_Node ( array ()), $lineno ));
41 $this- > parser
-> pushLocalScope ();
42 $this- > parser
-> pushBlockStack ( $name );
44 if ( $stream- > test ( Twig_Token
:: BLOCK_END_TYPE
)) {
47 $body = $this- > parser
-> subparse ( array ( $this , 'decideBlockEnd' ), true );
48 if ( $stream- > test ( Twig_Token
:: NAME_TYPE
)) {
49 $value = $stream- > next ()-> getValue ();
51 if ( $value != $name ) {
52 throw new Twig_Error_Syntax ( sprintf ( "Expected endblock for block ' $name' (but %s given)" , $value ), $stream- > getCurrent ()-> getLine (), $stream- > getFilename ());
56 $body = new Twig_Node ( array (
57 new Twig_Node_Print ( $this- > parser
-> getExpressionParser ()-> parseExpression (), $lineno ),
60 $stream- > expect ( Twig_Token
:: BLOCK_END_TYPE
);
62 $block- > setNode ( 'body' , $body );
63 $this- > parser
-> popBlockStack ();
64 $this- > parser
-> popLocalScope ();
66 return new Twig_Node_BlockReference ( $name , $lineno , $this- > getTag ());
69 public function decideBlockEnd ( Twig_Token
$token )
71 return $token- > test ( 'endblock' );
75 * Gets the tag name associated with this token parser.
77 * @return string The tag name
79 public function getTag ()