autoescape (string) - Sets the default auto-escaping strategy (name, html, js, css, url, html_attr, or a PHP callback that takes the template "filename" and returns the escaping strategy to use -- the callback cannot be a function name to avoid collision with built-in escaping strategies); set it to false to disable auto-escaping.
optimizations (int) - A flag that indicates which optimizations to apply (default to -1 -- all optimizations are enabled; set it to 0 to disable).
TwigEnvironmentFactory currently creating a new Environment instance using a limited list of options and Environment has no interface to set these options later but the construction.
This PR provides a compatible way for disabling optimizations and auto-escaping (which enabled by default) using configration:
$config = [
'twig' = [
'timezone' => 'UTC',
'cache_dir' => 'data/cache/twig',
// ... after all others
'autoescape' => false, // 'html' by default
'optimizations' => 0, // -1 by default
],
];
I have also wrote two test cases for these new options and considered using same values as Twig defaults in factory.
Only detail that bugging me is if Twig decides to change these defaults in a future release, TwigEnvironmentFactory would also need to be adjusted to reflect this changes.
Twig Environment provides following additional options for developers:
autoescape (string)
- Sets the default auto-escaping strategy (name, html, js, css, url, html_attr, or a PHP callback that takes the template "filename" and returns the escaping strategy to use -- the callback cannot be a function name to avoid collision with built-in escaping strategies); set it to false to disable auto-escaping.optimizations (int)
- A flag that indicates which optimizations to apply (default to-1
-- all optimizations are enabled; set it to 0 to disable).TwigEnvironmentFactory
currently creating a new Environment instance using a limited list of options and Environment has no interface to set these options later but the construction.This PR provides a compatible way for disabling optimizations and auto-escaping (which enabled by default) using configration:
I have also wrote two test cases for these new options and considered using same values as Twig defaults in factory.
Only detail that bugging me is if Twig decides to change these defaults in a future release,
TwigEnvironmentFactory
would also need to be adjusted to reflect this changes.