diff options
| author | Nathan Guse <nathaniel.guse@gmail.com> | 2013-06-10 00:59:06 -0500 | 
|---|---|---|
| committer | Nathan Guse <nathaniel.guse@gmail.com> | 2013-06-10 00:59:06 -0500 | 
| commit | 9f8f500ba33963a28c656af8a28a9a6521af4616 (patch) | |
| tree | 322708a8a772c13571bf2b1fc8ea304aa0bcc822 | |
| parent | 87cc8af26565dc1547383aa8c969cc5be48f0944 (diff) | |
| download | forums-9f8f500ba33963a28c656af8a28a9a6521af4616.tar forums-9f8f500ba33963a28c656af8a28a9a6521af4616.tar.gz forums-9f8f500ba33963a28c656af8a28a9a6521af4616.tar.bz2 forums-9f8f500ba33963a28c656af8a28a9a6521af4616.tar.xz forums-9f8f500ba33963a28c656af8a28a9a6521af4616.zip  | |
[feature/twig] Working on DEFINE
PHPBB3-11598
| -rw-r--r-- | phpBB/includes/template/twig/extension.php | 1 | ||||
| -rw-r--r-- | phpBB/includes/template/twig/lexer.php | 15 | ||||
| -rw-r--r-- | phpBB/includes/template/twig/tokenparser/define.php | 45 | 
3 files changed, 60 insertions, 1 deletions
diff --git a/phpBB/includes/template/twig/extension.php b/phpBB/includes/template/twig/extension.php index 29020fcf8e..bf4b0e8c54 100644 --- a/phpBB/includes/template/twig/extension.php +++ b/phpBB/includes/template/twig/extension.php @@ -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,  		);  	} diff --git a/phpBB/includes/template/twig/lexer.php b/phpBB/includes/template/twig/lexer.php index 70a21307ec..f60c58249c 100644 --- a/phpBB/includes/template/twig/lexer.php +++ b/phpBB/includes/template/twig/lexer.php @@ -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]); +	        } +		}  	}  } diff --git a/phpBB/includes/template/twig/tokenparser/define.php b/phpBB/includes/template/twig/tokenparser/define.php new file mode 100644 index 0000000000..8eb33c7ff9 --- /dev/null +++ b/phpBB/includes/template/twig/tokenparser/define.php @@ -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'; +    } +}  | 
