mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[feature/twig] Working on DEFINE
PHPBB3-11598
This commit is contained in:
parent
87cc8af265
commit
9f8f500ba3
3 changed files with 60 additions and 1 deletions
|
@ -29,6 +29,7 @@ class phpbb_template_twig_extension extends Twig_Extension
|
|||
new phpbb_template_twig_tokenparser_include,
|
||||
new phpbb_template_twig_tokenparser_event,
|
||||
new phpbb_template_twig_tokenparser_begin,
|
||||
new phpbb_template_twig_tokenparser_define,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,11 +42,24 @@ class phpbb_template_twig_lexer extends Twig_Lexer
|
|||
*/
|
||||
if ($last_element->getValue() === 'IF')
|
||||
{
|
||||
if (preg_match('#^\s*\.([a-zA-Z0-9\.]+)#', substr($this->code, $this->cursor), $match))
|
||||
if (preg_match('#^\s*\.([a-zA-Z0-9_\.]+)#', substr($this->code, $this->cursor), $match))
|
||||
{
|
||||
$this->pushToken(Twig_Token::STRING_TYPE, stripcslashes($match[1]));
|
||||
$this->moveCursor($match[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is some compatibility code to continue supporting expressions such as:
|
||||
* <!-- DEFINE $VAR = 'foo' -->
|
||||
*/
|
||||
if ($last_element->getValue() === 'DEFINE')
|
||||
{
|
||||
if (preg_match('#^\s*\$([A-Z0-9]+)#', substr($this->code, $this->cursor), $match))
|
||||
{
|
||||
$this->pushToken(Twig_Token::STRING_TYPE, stripcslashes($match[1]));
|
||||
$this->moveCursor($match[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
45
phpBB/includes/template/twig/tokenparser/define.php
Normal file
45
phpBB/includes/template/twig/tokenparser/define.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines a variable.
|
||||
*
|
||||
* <pre>
|
||||
* {% set foo = 'foo' %}
|
||||
*
|
||||
* {% set foo = [1, 2] %}
|
||||
*
|
||||
* {% set foo = {'foo': 'bar'} %}
|
||||
*
|
||||
* {% set foo = 'foo' ~ 'bar' %}
|
||||
*
|
||||
* {% set foo, bar = 'foo', 'bar' %}
|
||||
*
|
||||
* {% set foo %}Some content{% endset %}
|
||||
* </pre>
|
||||
*/
|
||||
class phpbb_template_twig_tokenparser_define extends Twig_TokenParser_Set
|
||||
{
|
||||
public function decideBlockEnd(Twig_Token $token)
|
||||
{
|
||||
return $token->test('ENDDEFINE');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the tag name associated with this token parser.
|
||||
*
|
||||
* @return string The tag name
|
||||
*/
|
||||
public function getTag()
|
||||
{
|
||||
return 'DEFINE';
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue