mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 23:45:20 +02:00
[ticket/16885] Add type casting filters to Twig
PHPBB3-16885
This commit is contained in:
parent
ea36b83ee9
commit
13155bf846
@ -79,8 +79,8 @@ class extension extends \Twig\Extension\AbstractExtension
|
|||||||
new \Twig\TwigFilter('subset', array($this, 'loop_subset'), array('needs_environment' => true)),
|
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
|
// @deprecated 3.2.0 Uses twig's JS escape method instead of addslashes
|
||||||
new \Twig\TwigFilter('addslashes', 'addslashes'),
|
new \Twig\TwigFilter('addslashes', 'addslashes'),
|
||||||
new \Twig\TwigFilter('int', [$this, 'type_int']),
|
new \Twig\TwigFilter('int', 'intval'),
|
||||||
new \Twig\TwigFilter('float', [$this, 'type_float']),
|
new \Twig\TwigFilter('float', 'floatval'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,28 +167,6 @@ class extension extends \Twig\Extension\AbstractExtension
|
|||||||
return twig_slice($env, $item, $start, $end, $preserveKeys);
|
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)
|
* Get output for a language variable (L_FOO, LA_FOO)
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user