mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-11 22:08:54 +00:00
[feature/twig] Some additional operators, more stuff for IF
PHPBB3-11598
This commit is contained in:
parent
95884edf08
commit
74f19830f3
6 changed files with 55 additions and 5 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,5 +1,6 @@
|
||||||
*~
|
*~
|
||||||
/phpunit.xml
|
/phpunit.xml
|
||||||
|
/phpBB/cache/twig/*
|
||||||
/phpBB/cache/*.html
|
/phpBB/cache/*.html
|
||||||
/phpBB/cache/*.php
|
/phpBB/cache/*.php
|
||||||
/phpBB/cache/*.lock
|
/phpBB/cache/*.lock
|
||||||
|
|
|
@ -39,8 +39,20 @@ class phpbb_template_twig_extension extends Twig_Extension
|
||||||
return array(
|
return array(
|
||||||
array(),
|
array(),
|
||||||
array(
|
array(
|
||||||
|
// @todo check if all these are needed (or others)
|
||||||
'eq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Equal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
|
'eq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Equal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
|
||||||
'!==' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
|
|
||||||
|
'ne' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
|
||||||
|
'neq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
|
||||||
|
'<>' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
|
||||||
|
|
||||||
|
'===' => array('precedence' => 20, 'class' => 'phpbb_template_twig_node_expression_binary_equalequal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
|
||||||
|
'!==' => array('precedence' => 20, 'class' => 'phpbb_template_twig_node_expression_binary_notequalequal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
|
||||||
|
|
||||||
|
'gt' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Greater', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
|
||||||
|
'gte' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
|
||||||
|
'lt' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Less', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
|
||||||
|
'lte' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ class phpbb_template_twig_lexer extends Twig_Lexer
|
||||||
// This strips the $ inside of a tag directly after the token, which was used in <!-- DEFINE $NAME
|
// This strips the $ inside of a tag directly after the token, which was used in <!-- DEFINE $NAME
|
||||||
$code = preg_replace('#<!-- DEFINE \$(.*)-->#', '<!-- DEFINE $1-->', $code);
|
$code = preg_replace('#<!-- DEFINE \$(.*)-->#', '<!-- DEFINE $1-->', $code);
|
||||||
|
|
||||||
// This strips the . inside of a tag directly before a variable name, which was used in <!-- IF .blah
|
// This strips the . or $ inside of a tag directly before a variable name, which was used in <!-- IF .blah
|
||||||
$code = preg_replace_callback('#<!-- IF((.*)[\s][\$|\.]([^\s]+)(.*))-->#', array($this, 'tag_if_cleanup'), $code);
|
$code = preg_replace_callback('#<!-- IF((.*)[\s][\$|\.]([^\s]+)(.*))-->#', array($this, 'tag_if_cleanup'), $code);
|
||||||
|
|
||||||
// Replace all of our starting tokens, <!-- TOKEN --> with Twig style, {% TOKEN %}
|
// Replace all of our starting tokens, <!-- TOKEN --> with Twig style, {% TOKEN %}
|
||||||
|
@ -61,12 +61,13 @@ class phpbb_template_twig_lexer extends Twig_Lexer
|
||||||
/**
|
/**
|
||||||
* preg_replace_callback to clean up IF statements
|
* preg_replace_callback to clean up IF statements
|
||||||
*
|
*
|
||||||
* This strips the . inside of a tag directly before a variable name, which was used in <!-- IF .blah
|
* This strips the . or $ inside of a tag directly before a variable name.
|
||||||
|
* Was used in <!-- IF .blah or <!-- IF $BLAH
|
||||||
*
|
*
|
||||||
* @param mixed $matches
|
* @param mixed $matches
|
||||||
*/
|
*/
|
||||||
protected function tag_if_cleanup($matches)
|
protected function tag_if_cleanup($matches)
|
||||||
{
|
{
|
||||||
return '<!-- IF ' . preg_replace('#\s\.([a-zA-Z_0-9]+)#', ' $1', $matches[1]) . ' -->';
|
return '<!-- IF ' . preg_replace('#\s[\.|\$]([a-zA-Z_0-9]+)#', ' $1', $matches[1]) . ' -->';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
* @copyright (c) 2013 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class phpbb_template_twig_node_expression_binary_equalequal extends Twig_Node_Expression_Binary
|
||||||
|
{
|
||||||
|
public function operator(Twig_Compiler $compiler)
|
||||||
|
{
|
||||||
|
return $compiler->raw('===');
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
* @copyright (c) 2013 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class phpbb_template_twig_node_expression_binary_notequalequal extends Twig_Node_Expression_Binary
|
||||||
|
{
|
||||||
|
public function operator(Twig_Compiler $compiler)
|
||||||
|
{
|
||||||
|
return $compiler->raw('!==');
|
||||||
|
}
|
||||||
|
}
|
|
@ -108,13 +108,17 @@ class phpbb_template_twig implements phpbb_template
|
||||||
$this->extension_manager = $extension_manager;
|
$this->extension_manager = $extension_manager;
|
||||||
|
|
||||||
$loader = new Twig_Loader_Filesystem($phpbb_root_path . 'styles/prosilver/template/');
|
$loader = new Twig_Loader_Filesystem($phpbb_root_path . 'styles/prosilver/template/');
|
||||||
|
//$loader = new Twig_Loader_Filesystem($phpbb_root_path . 'adm/style/');
|
||||||
$this->twig = new Twig_Environment($loader, array(
|
$this->twig = new Twig_Environment($loader, array(
|
||||||
//'cache' => $phpbb_root_path . 'cache/twig/',
|
'cache' => $phpbb_root_path . 'cache/twig/',
|
||||||
'debug' => true,
|
'debug' => true,
|
||||||
'auto_reload' => true,
|
'auto_reload' => true,
|
||||||
'autoescape' => false,
|
'autoescape' => false,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// Clear previous cache files (while WIP)
|
||||||
|
$this->twig->clearCacheFiles();
|
||||||
|
|
||||||
$this->twig->addExtension(new phpbb_template_twig_extension);
|
$this->twig->addExtension(new phpbb_template_twig_extension);
|
||||||
|
|
||||||
$lexer = new phpbb_template_twig_lexer($this->twig);
|
$lexer = new phpbb_template_twig_lexer($this->twig);
|
||||||
|
|
Loading…
Add table
Reference in a new issue