1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-01-17 22:28:46 +01:00

[ticket/16885] Add type casting filters to Twig

PHPBB3-16885
This commit is contained in:
3D-I 2021-10-17 16:18:09 +02:00
parent ea36b83ee9
commit 13155bf846

View File

@ -79,8 +79,8 @@ class extension extends \Twig\Extension\AbstractExtension
new \Twig\TwigFilter('subset', array($this, 'loop_subset'), array('needs_environment' => true)),
// @deprecated 3.2.0 Uses twig's JS escape method instead of addslashes
new \Twig\TwigFilter('addslashes', 'addslashes'),
new \Twig\TwigFilter('int', [$this, 'type_int']),
new \Twig\TwigFilter('float', [$this, 'type_float']),
new \Twig\TwigFilter('int', 'intval'),
new \Twig\TwigFilter('float', 'floatval'),
);
}
@ -167,28 +167,6 @@ class extension extends \Twig\Extension\AbstractExtension
return twig_slice($env, $item, $start, $end, $preserveKeys);
}
/**
* Cast to INT a variable
*
* Example: config('my_awesome_config')|int
* @return int
*/
public function type_int($value)
{
return (int) $value;
}
/**
* Cast to FLOAT a variable
*
* Example: config('my_awesome_config')|float
* @return float
*/
public function type_float($value)
{
return (float) $value;
}
/**
* Get output for a language variable (L_FOO, LA_FOO)
*