[feature/twig] Fix indentation

PHPBB3-11598
This commit is contained in:
Nathaniel Guse 2013-07-02 12:34:16 -05:00
parent f102f609f5
commit 57c2d99e65
16 changed files with 353 additions and 342 deletions

View file

@ -29,6 +29,15 @@ class phpbb_template_twig_environment extends Twig_Environment
/** @var array **/ /** @var array **/
protected $namespace_look_up_order = array('__main__'); protected $namespace_look_up_order = array('__main__');
/**
* Constructor
*
* @param phpbb_config $phpbb_config
* @param array $phpbb_extensions Array of enabled extensions (name => path)
* @param string $phpbb_root_path
* @param Twig_LoaderInterface $loader
* @param array $options Array of options to pass to Twig
*/
public function __construct($phpbb_config, $phpbb_extensions, $phpbb_root_path, Twig_LoaderInterface $loader = null, $options = array()) public function __construct($phpbb_config, $phpbb_extensions, $phpbb_root_path, Twig_LoaderInterface $loader = null, $options = array())
{ {
$this->phpbb_config = $phpbb_config; $this->phpbb_config = $phpbb_config;
@ -41,6 +50,8 @@ class phpbb_template_twig_environment extends Twig_Environment
/** /**
* Get the list of enabled phpBB extensions * Get the list of enabled phpBB extensions
* *
* Used in EVENT node
*
* @return array * @return array
*/ */
public function get_phpbb_extensions() public function get_phpbb_extensions()

View file

@ -9,19 +9,19 @@
class phpbb_template_twig_node_define extends Twig_Node class phpbb_template_twig_node_define extends Twig_Node
{ {
public function __construct($capture, Twig_NodeInterface $name, Twig_NodeInterface $value, $lineno, $tag = null) public function __construct($capture, Twig_NodeInterface $name, Twig_NodeInterface $value, $lineno, $tag = null)
{ {
parent::__construct(array('name' => $name, 'value' => $value), array('capture' => $capture, 'safe' => false), $lineno, $tag); parent::__construct(array('name' => $name, 'value' => $value), array('capture' => $capture, 'safe' => false), $lineno, $tag);
} }
/** /**
* Compiles the node to PHP. * Compiles the node to PHP.
* *
* @param Twig_Compiler A Twig_Compiler instance * @param Twig_Compiler A Twig_Compiler instance
*/ */
public function compile(Twig_Compiler $compiler) public function compile(Twig_Compiler $compiler)
{ {
$compiler->addDebugInfo($this); $compiler->addDebugInfo($this);
if ($this->getAttribute('capture')) { if ($this->getAttribute('capture')) {
$compiler $compiler
@ -45,5 +45,5 @@ class phpbb_template_twig_node_define extends Twig_Node
->raw($this->getNode('name')->getAttribute('name')) ->raw($this->getNode('name')->getAttribute('name'))
->raw("', \$value);\n") ->raw("', \$value);\n")
; ;
} }
} }

View file

@ -12,39 +12,39 @@ class phpbb_template_twig_node_event extends Twig_Node
/** @var Twig_Environment */ /** @var Twig_Environment */
protected $environment; protected $environment;
public function __construct(Twig_Node_Expression $expr, phpbb_template_twig_environment $environment, $lineno, $tag = null) public function __construct(Twig_Node_Expression $expr, phpbb_template_twig_environment $environment, $lineno, $tag = null)
{ {
$this->environment = $environment; $this->environment = $environment;
parent::__construct(array('expr' => $expr), array(), $lineno, $tag); parent::__construct(array('expr' => $expr), array(), $lineno, $tag);
} }
/** /**
* Compiles the node to PHP. * Compiles the node to PHP.
* *
* @param Twig_Compiler A Twig_Compiler instance * @param Twig_Compiler A Twig_Compiler instance
*/ */
public function compile(Twig_Compiler $compiler) public function compile(Twig_Compiler $compiler)
{ {
$compiler->addDebugInfo($this); $compiler->addDebugInfo($this);
$location = $this->getNode('expr')->getAttribute('name'); $location = $this->getNode('expr')->getAttribute('name');
foreach ($this->environment->get_phpbb_extensions() as $ext_namespace => $ext_path) foreach ($this->environment->get_phpbb_extensions() as $ext_namespace => $ext_path)
{ {
$ext_namespace = str_replace('/', '_', $ext_namespace); $ext_namespace = str_replace('/', '_', $ext_namespace);
if ($this->environment->getLoader()->exists('@' . $ext_namespace . '/' . $location . '.html')) if ($this->environment->getLoader()->exists('@' . $ext_namespace . '/' . $location . '.html'))
{ {
$compiler $compiler
->write("\$previous_look_up_order = \$this->env->getNamespaceLookUpOrder();\n") ->write("\$previous_look_up_order = \$this->env->getNamespaceLookUpOrder();\n")
// We set the namespace lookup order to be this extension first, then the main path // We set the namespace lookup order to be this extension first, then the main path
->write("\$this->env->setNamespaceLookUpOrder(array('" . $ext_namespace . "', '__main__'));\n") ->write("\$this->env->setNamespaceLookUpOrder(array('" . $ext_namespace . "', '__main__'));\n")
->write("\$this->env->loadTemplate('@" . $ext_namespace . "/" . $location . ".html')->display(\$context);\n") ->write("\$this->env->loadTemplate('@" . $ext_namespace . "/" . $location . ".html')->display(\$context);\n")
->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n") ->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n")
; ;
} }
} }
} }
} }

View file

@ -9,8 +9,8 @@
class phpbb_template_twig_node_expression_binary_equalequal extends Twig_Node_Expression_Binary class phpbb_template_twig_node_expression_binary_equalequal extends Twig_Node_Expression_Binary
{ {
public function operator(Twig_Compiler $compiler) public function operator(Twig_Compiler $compiler)
{ {
return $compiler->raw('==='); return $compiler->raw('===');
} }
} }

View file

@ -9,8 +9,8 @@
class phpbb_template_twig_node_expression_binary_notequalequal extends Twig_Node_Expression_Binary class phpbb_template_twig_node_expression_binary_notequalequal extends Twig_Node_Expression_Binary
{ {
public function operator(Twig_Compiler $compiler) public function operator(Twig_Compiler $compiler)
{ {
return $compiler->raw('!=='); return $compiler->raw('!==');
} }
} }

View file

@ -9,14 +9,14 @@
class phpbb_template_twig_node_include extends Twig_Node_Include class phpbb_template_twig_node_include extends Twig_Node_Include
{ {
/** /**
* Compiles the node to PHP. * Compiles the node to PHP.
* *
* @param Twig_Compiler A Twig_Compiler instance * @param Twig_Compiler A Twig_Compiler instance
*/ */
public function compile(Twig_Compiler $compiler) public function compile(Twig_Compiler $compiler)
{ {
$compiler->addDebugInfo($this); $compiler->addDebugInfo($this);
$compiler $compiler
->write("\$location = ") ->write("\$location = ")
@ -26,15 +26,15 @@ class phpbb_template_twig_node_include extends Twig_Node_Include
->write("if (strpos(\$location, '@') === 0) {\n") ->write("if (strpos(\$location, '@') === 0) {\n")
->indent() ->indent()
->write("\$namespace = substr(\$location, 1, strpos(\$location, '/') - 1);\n") ->write("\$namespace = substr(\$location, 1, strpos(\$location, '/') - 1);\n")
->write("\$previous_look_up_order = \$this->env->getNamespaceLookUpOrder();\n") ->write("\$previous_look_up_order = \$this->env->getNamespaceLookUpOrder();\n")
// We set the namespace lookup order to be this namespace first, then the main path // We set the namespace lookup order to be this namespace first, then the main path
->write("\$this->env->setNamespaceLookUpOrder(array(\$namespace, '__main__'));\n") ->write("\$this->env->setNamespaceLookUpOrder(array(\$namespace, '__main__'));\n")
->outdent() ->outdent()
->write("}\n") ->write("}\n")
; ;
parent::compile($compiler); parent::compile($compiler);
$compiler $compiler
->write("if (\$namespace) {\n") ->write("if (\$namespace) {\n")
@ -42,6 +42,6 @@ class phpbb_template_twig_node_include extends Twig_Node_Include
->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n") ->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n")
->outdent() ->outdent()
->write("}\n") ->write("}\n")
; ;
} }
} }

View file

@ -12,27 +12,27 @@ class phpbb_template_twig_node_includejs extends Twig_Node
/** @var Twig_Environment */ /** @var Twig_Environment */
protected $environment; protected $environment;
public function __construct(Twig_Node_Expression $expr, phpbb_template_twig_environment $environment, $lineno, $tag = null) public function __construct(Twig_Node_Expression $expr, phpbb_template_twig_environment $environment, $lineno, $tag = null)
{ {
$this->environment = $environment; $this->environment = $environment;
parent::__construct(array('expr' => $expr), array(), $lineno, $tag); parent::__construct(array('expr' => $expr), array(), $lineno, $tag);
} }
/** /**
* Compiles the node to PHP. * Compiles the node to PHP.
* *
* @param Twig_Compiler A Twig_Compiler instance * @param Twig_Compiler A Twig_Compiler instance
*/ */
public function compile(Twig_Compiler $compiler) public function compile(Twig_Compiler $compiler)
{ {
$compiler->addDebugInfo($this); $compiler->addDebugInfo($this);
$config = $this->environment->get_phpbb_config(); $config = $this->environment->get_phpbb_config();
$compiler $compiler
->write("\$js_file = ") ->write("\$js_file = ")
->subcompile($this->getNode('expr')) ->subcompile($this->getNode('expr'))
->raw(";\n") ->raw(";\n")
->write("if (!file_exists(\$js_file)) {\n") ->write("if (!file_exists(\$js_file)) {\n")
->indent() ->indent()
@ -41,7 +41,7 @@ class phpbb_template_twig_node_includejs extends Twig_Node
->write("}\n") ->write("}\n")
->write("\$context['definition']->append('SCRIPTS', '<script type=\"text/javascript\" src=\"' . ") ->write("\$context['definition']->append('SCRIPTS', '<script type=\"text/javascript\" src=\"' . ")
->raw("\$js_file") ->raw("\$js_file")
->raw(" . '?assets_version=" . $config['assets_version'] . "\"></script>\n');\n") ->raw(" . '?assets_version=" . $config['assets_version'] . "\"></script>\n');\n")
; ;
} }
} }

View file

@ -12,21 +12,21 @@ class phpbb_template_twig_node_includephp extends Twig_Node
/** @var Twig_Environment */ /** @var Twig_Environment */
protected $environment; protected $environment;
public function __construct(Twig_Node_Expression $expr, phpbb_template_twig_environment $environment, $ignoreMissing = false, $lineno, $tag = null) public function __construct(Twig_Node_Expression $expr, phpbb_template_twig_environment $environment, $ignoreMissing = false, $lineno, $tag = null)
{ {
$this->environment = $environment; $this->environment = $environment;
parent::__construct(array('expr' => $expr), array('ignore_missing' => (Boolean) $ignoreMissing), $lineno, $tag); parent::__construct(array('expr' => $expr), array('ignore_missing' => (Boolean) $ignoreMissing), $lineno, $tag);
} }
/** /**
* Compiles the node to PHP. * Compiles the node to PHP.
* *
* @param Twig_Compiler A Twig_Compiler instance * @param Twig_Compiler A Twig_Compiler instance
*/ */
public function compile(Twig_Compiler $compiler) public function compile(Twig_Compiler $compiler)
{ {
$compiler->addDebugInfo($this); $compiler->addDebugInfo($this);
$config = $this->environment->get_phpbb_config(); $config = $this->environment->get_phpbb_config();
@ -39,12 +39,12 @@ class phpbb_template_twig_node_includephp extends Twig_Node
return; return;
} }
if ($this->getAttribute('ignore_missing')) { if ($this->getAttribute('ignore_missing')) {
$compiler $compiler
->write("try {\n") ->write("try {\n")
->indent() ->indent()
; ;
} }
$compiler $compiler
->write("\$location = ") ->write("\$location = ")
@ -68,15 +68,15 @@ class phpbb_template_twig_node_includephp extends Twig_Node
->write("}\n") ->write("}\n")
; ;
if ($this->getAttribute('ignore_missing')) { if ($this->getAttribute('ignore_missing')) {
$compiler $compiler
->outdent() ->outdent()
->write("} catch (Twig_Error_Loader \$e) {\n") ->write("} catch (Twig_Error_Loader \$e) {\n")
->indent() ->indent()
->write("// ignore missing template\n") ->write("// ignore missing template\n")
->outdent() ->outdent()
->write("}\n\n") ->write("}\n\n")
; ;
} }
} }
} }

View file

@ -12,21 +12,21 @@ class phpbb_template_twig_node_php extends Twig_Node
/** @var Twig_Environment */ /** @var Twig_Environment */
protected $environment; protected $environment;
public function __construct(Twig_Node_Text $text, phpbb_template_twig_environment $environment, $lineno, $tag = null) public function __construct(Twig_Node_Text $text, phpbb_template_twig_environment $environment, $lineno, $tag = null)
{ {
$this->environment = $environment; $this->environment = $environment;
parent::__construct(array('text' => $text), array(), $lineno, $tag); parent::__construct(array('text' => $text), array(), $lineno, $tag);
} }
/** /**
* Compiles the node to PHP. * Compiles the node to PHP.
* *
* @param Twig_Compiler A Twig_Compiler instance * @param Twig_Compiler A Twig_Compiler instance
*/ */
public function compile(Twig_Compiler $compiler) public function compile(Twig_Compiler $compiler)
{ {
$compiler->addDebugInfo($this); $compiler->addDebugInfo($this);
$config = $this->environment->get_phpbb_config(); $config = $this->environment->get_phpbb_config();
@ -42,5 +42,5 @@ class phpbb_template_twig_node_php extends Twig_Node
$compiler $compiler
->raw($this->getNode('text')->getAttribute('data')) ->raw($this->getNode('text')->getAttribute('data'))
; ;
} }
} }

View file

@ -9,49 +9,49 @@
class phpbb_template_twig_tokenparser_define extends Twig_TokenParser class phpbb_template_twig_tokenparser_define extends Twig_TokenParser
{ {
/** /**
* Parses a token and returns a node. * Parses a token and returns a node.
* *
* @param Twig_Token $token A Twig_Token instance * @param Twig_Token $token A Twig_Token instance
* *
* @return Twig_NodeInterface A Twig_NodeInterface instance * @return Twig_NodeInterface A Twig_NodeInterface instance
*/ */
public function parse(Twig_Token $token) public function parse(Twig_Token $token)
{ {
$lineno = $token->getLine(); $lineno = $token->getLine();
$stream = $this->parser->getStream(); $stream = $this->parser->getStream();
$name = $this->parser->getExpressionParser()->parseExpression(); $name = $this->parser->getExpressionParser()->parseExpression();
$capture = false; $capture = false;
if ($stream->test(Twig_Token::OPERATOR_TYPE, '=')) { if ($stream->test(Twig_Token::OPERATOR_TYPE, '=')) {
$stream->next(); $stream->next();
$value = $this->parser->getExpressionParser()->parseExpression(); $value = $this->parser->getExpressionParser()->parseExpression();
$stream->expect(Twig_Token::BLOCK_END_TYPE); $stream->expect(Twig_Token::BLOCK_END_TYPE);
} else { } else {
$capture = true; $capture = true;
$stream->expect(Twig_Token::BLOCK_END_TYPE); $stream->expect(Twig_Token::BLOCK_END_TYPE);
$value = $this->parser->subparse(array($this, 'decideBlockEnd'), true); $value = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
$stream->expect(Twig_Token::BLOCK_END_TYPE); $stream->expect(Twig_Token::BLOCK_END_TYPE);
} }
return new phpbb_template_twig_node_define($capture, $name, $value, $lineno, $this->getTag()); return new phpbb_template_twig_node_define($capture, $name, $value, $lineno, $this->getTag());
} }
public function decideBlockEnd(Twig_Token $token) public function decideBlockEnd(Twig_Token $token)
{ {
return $token->test('ENDDEFINE'); return $token->test('ENDDEFINE');
} }
/** /**
* Gets the tag name associated with this token parser. * Gets the tag name associated with this token parser.
* *
* @return string The tag name * @return string The tag name
*/ */
public function getTag() public function getTag()
{ {
return 'DEFINE'; return 'DEFINE';
} }
} }

View file

@ -9,30 +9,30 @@
class phpbb_template_twig_tokenparser_event extends Twig_TokenParser class phpbb_template_twig_tokenparser_event extends Twig_TokenParser
{ {
/** /**
* Parses a token and returns a node. * Parses a token and returns a node.
* *
* @param Twig_Token $token A Twig_Token instance * @param Twig_Token $token A Twig_Token instance
* *
* @return Twig_NodeInterface A Twig_NodeInterface instance * @return Twig_NodeInterface A Twig_NodeInterface instance
*/ */
public function parse(Twig_Token $token) public function parse(Twig_Token $token)
{ {
$expr = $this->parser->getExpressionParser()->parseExpression(); $expr = $this->parser->getExpressionParser()->parseExpression();
$stream = $this->parser->getStream(); $stream = $this->parser->getStream();
$stream->expect(Twig_Token::BLOCK_END_TYPE); $stream->expect(Twig_Token::BLOCK_END_TYPE);
return new phpbb_template_twig_node_event($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag()); return new phpbb_template_twig_node_event($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag());
} }
/** /**
* Gets the tag name associated with this token parser. * Gets the tag name associated with this token parser.
* *
* @return string The tag name * @return string The tag name
*/ */
public function getTag() public function getTag()
{ {
return 'EVENT'; return 'EVENT';
} }
} }

View file

@ -9,70 +9,70 @@
class phpbb_template_twig_tokenparser_if extends Twig_TokenParser_If class phpbb_template_twig_tokenparser_if extends Twig_TokenParser_If
{ {
/** /**
* Parses a token and returns a node. * Parses a token and returns a node.
* *
* @param Twig_Token $token A Twig_Token instance * @param Twig_Token $token A Twig_Token instance
* *
* @return Twig_NodeInterface A Twig_NodeInterface instance * @return Twig_NodeInterface A Twig_NodeInterface instance
*/ */
public function parse(Twig_Token $token) public function parse(Twig_Token $token)
{ {
$lineno = $token->getLine(); $lineno = $token->getLine();
$expr = $this->parser->getExpressionParser()->parseExpression(); $expr = $this->parser->getExpressionParser()->parseExpression();
$stream = $this->parser->getStream(); $stream = $this->parser->getStream();
$stream->expect(Twig_Token::BLOCK_END_TYPE); $stream->expect(Twig_Token::BLOCK_END_TYPE);
$body = $this->parser->subparse(array($this, 'decideIfFork')); $body = $this->parser->subparse(array($this, 'decideIfFork'));
$tests = array($expr, $body); $tests = array($expr, $body);
$else = null; $else = null;
$end = false; $end = false;
while (!$end) { while (!$end) {
switch ($stream->next()->getValue()) { switch ($stream->next()->getValue()) {
case 'ELSE': case 'ELSE':
$stream->expect(Twig_Token::BLOCK_END_TYPE); $stream->expect(Twig_Token::BLOCK_END_TYPE);
$else = $this->parser->subparse(array($this, 'decideIfEnd')); $else = $this->parser->subparse(array($this, 'decideIfEnd'));
break; break;
case 'ELSEIF': case 'ELSEIF':
$expr = $this->parser->getExpressionParser()->parseExpression(); $expr = $this->parser->getExpressionParser()->parseExpression();
$stream->expect(Twig_Token::BLOCK_END_TYPE); $stream->expect(Twig_Token::BLOCK_END_TYPE);
$body = $this->parser->subparse(array($this, 'decideIfFork')); $body = $this->parser->subparse(array($this, 'decideIfFork'));
$tests[] = $expr; $tests[] = $expr;
$tests[] = $body; $tests[] = $body;
break; break;
case 'ENDIF': case 'ENDIF':
$end = true; $end = true;
break; break;
default: default:
throw new Twig_Error_Syntax(sprintf('Unexpected end of template. Twig was looking for the following tags "ELSE", "ELSEIF", or "ENDIF" to close the "IF" block started at line %d)', $lineno), $stream->getCurrent()->getLine(), $stream->getFilename()); throw new Twig_Error_Syntax(sprintf('Unexpected end of template. Twig was looking for the following tags "ELSE", "ELSEIF", or "ENDIF" to close the "IF" block started at line %d)', $lineno), $stream->getCurrent()->getLine(), $stream->getFilename());
} }
} }
$stream->expect(Twig_Token::BLOCK_END_TYPE); $stream->expect(Twig_Token::BLOCK_END_TYPE);
return new Twig_Node_If(new Twig_Node($tests), $else, $lineno, $this->getTag()); return new Twig_Node_If(new Twig_Node($tests), $else, $lineno, $this->getTag());
} }
public function decideIfFork(Twig_Token $token) public function decideIfFork(Twig_Token $token)
{ {
return $token->test(array('ELSEIF', 'ELSE', 'ENDIF')); return $token->test(array('ELSEIF', 'ELSE', 'ENDIF'));
} }
public function decideIfEnd(Twig_Token $token) public function decideIfEnd(Twig_Token $token)
{ {
return $token->test(array('ENDIF')); return $token->test(array('ENDIF'));
} }
/** /**
* Gets the tag name associated with this token parser. * Gets the tag name associated with this token parser.
* *
* @return string The tag name * @return string The tag name
*/ */
public function getTag() public function getTag()
{ {
return 'IF'; return 'IF';
} }
} }

View file

@ -9,29 +9,29 @@
class phpbb_template_twig_tokenparser_include extends Twig_TokenParser_Include class phpbb_template_twig_tokenparser_include extends Twig_TokenParser_Include
{ {
/** /**
* Parses a token and returns a node. * Parses a token and returns a node.
* *
* @param Twig_Token $token A Twig_Token instance * @param Twig_Token $token A Twig_Token instance
* *
* @return Twig_NodeInterface A Twig_NodeInterface instance * @return Twig_NodeInterface A Twig_NodeInterface instance
*/ */
public function parse(Twig_Token $token) public function parse(Twig_Token $token)
{ {
$expr = $this->parser->getExpressionParser()->parseExpression(); $expr = $this->parser->getExpressionParser()->parseExpression();
list($variables, $only, $ignoreMissing) = $this->parseArguments(); list($variables, $only, $ignoreMissing) = $this->parseArguments();
return new phpbb_template_twig_node_include($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); return new phpbb_template_twig_node_include($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag());
} }
/** /**
* Gets the tag name associated with this token parser. * Gets the tag name associated with this token parser.
* *
* @return string The tag name * @return string The tag name
*/ */
public function getTag() public function getTag()
{ {
return 'INCLUDE'; return 'INCLUDE';
} }
} }

View file

@ -9,30 +9,30 @@
class phpbb_template_twig_tokenparser_includejs extends Twig_TokenParser class phpbb_template_twig_tokenparser_includejs extends Twig_TokenParser
{ {
/** /**
* Parses a token and returns a node. * Parses a token and returns a node.
* *
* @param Twig_Token $token A Twig_Token instance * @param Twig_Token $token A Twig_Token instance
* *
* @return Twig_NodeInterface A Twig_NodeInterface instance * @return Twig_NodeInterface A Twig_NodeInterface instance
*/ */
public function parse(Twig_Token $token) public function parse(Twig_Token $token)
{ {
$expr = $this->parser->getExpressionParser()->parseExpression(); $expr = $this->parser->getExpressionParser()->parseExpression();
$stream = $this->parser->getStream(); $stream = $this->parser->getStream();
$stream->expect(Twig_Token::BLOCK_END_TYPE); $stream->expect(Twig_Token::BLOCK_END_TYPE);
return new phpbb_template_twig_node_includejs($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag()); return new phpbb_template_twig_node_includejs($expr, $this->parser->getEnvironment(), $token->getLine(), $this->getTag());
} }
/** /**
* Gets the tag name associated with this token parser. * Gets the tag name associated with this token parser.
* *
* @return string The tag name * @return string The tag name
*/ */
public function getTag() public function getTag()
{ {
return 'INCLUDEJS'; return 'INCLUDEJS';
} }
} }

View file

@ -9,39 +9,39 @@
class phpbb_template_twig_tokenparser_includephp extends Twig_TokenParser class phpbb_template_twig_tokenparser_includephp extends Twig_TokenParser
{ {
/** /**
* Parses a token and returns a node. * Parses a token and returns a node.
* *
* @param Twig_Token $token A Twig_Token instance * @param Twig_Token $token A Twig_Token instance
* *
* @return Twig_NodeInterface A Twig_NodeInterface instance * @return Twig_NodeInterface A Twig_NodeInterface instance
*/ */
public function parse(Twig_Token $token) public function parse(Twig_Token $token)
{ {
$expr = $this->parser->getExpressionParser()->parseExpression(); $expr = $this->parser->getExpressionParser()->parseExpression();
$stream = $this->parser->getStream(); $stream = $this->parser->getStream();
$ignoreMissing = false; $ignoreMissing = false;
if ($stream->test(Twig_Token::NAME_TYPE, 'ignore')) { if ($stream->test(Twig_Token::NAME_TYPE, 'ignore')) {
$stream->next(); $stream->next();
$stream->expect(Twig_Token::NAME_TYPE, 'missing'); $stream->expect(Twig_Token::NAME_TYPE, 'missing');
$ignoreMissing = true; $ignoreMissing = true;
} }
$stream->expect(Twig_Token::BLOCK_END_TYPE); $stream->expect(Twig_Token::BLOCK_END_TYPE);
return new phpbb_template_twig_node_includephp($expr, $this->parser->getEnvironment(), $ignoreMissing, $token->getLine(), $this->getTag()); return new phpbb_template_twig_node_includephp($expr, $this->parser->getEnvironment(), $ignoreMissing, $token->getLine(), $this->getTag());
} }
/** /**
* Gets the tag name associated with this token parser. * Gets the tag name associated with this token parser.
* *
* @return string The tag name * @return string The tag name
*/ */
public function getTag() public function getTag()
{ {
return 'INCLUDEPHP'; return 'INCLUDEPHP';
} }
} }

View file

@ -9,38 +9,38 @@
class phpbb_template_twig_tokenparser_php extends Twig_TokenParser class phpbb_template_twig_tokenparser_php extends Twig_TokenParser
{ {
/** /**
* Parses a token and returns a node. * Parses a token and returns a node.
* *
* @param Twig_Token $token A Twig_Token instance * @param Twig_Token $token A Twig_Token instance
* *
* @return Twig_NodeInterface A Twig_NodeInterface instance * @return Twig_NodeInterface A Twig_NodeInterface instance
*/ */
public function parse(Twig_Token $token) public function parse(Twig_Token $token)
{ {
$stream = $this->parser->getStream(); $stream = $this->parser->getStream();
$stream->expect(Twig_Token::BLOCK_END_TYPE); $stream->expect(Twig_Token::BLOCK_END_TYPE);
$body = $this->parser->subparse(array($this, 'decideEnd'), true); $body = $this->parser->subparse(array($this, 'decideEnd'), true);
$stream->expect(Twig_Token::BLOCK_END_TYPE); $stream->expect(Twig_Token::BLOCK_END_TYPE);
return new phpbb_template_twig_node_php($body, $this->parser->getEnvironment(), $token->getLine(), $this->getTag()); return new phpbb_template_twig_node_php($body, $this->parser->getEnvironment(), $token->getLine(), $this->getTag());
} }
public function decideEnd(Twig_Token $token) public function decideEnd(Twig_Token $token)
{ {
return $token->test('ENDPHP'); return $token->test('ENDPHP');
} }
/** /**
* Gets the tag name associated with this token parser. * Gets the tag name associated with this token parser.
* *
* @return string The tag name * @return string The tag name
*/ */
public function getTag() public function getTag()
{ {
return 'PHP'; return 'PHP';
} }
} }