public TwigEnvironment::__construct($root, CacheBackendInterface $cache, $twig_extension_hash, \Twig_LoaderInterface $loader = NULL, $options = array())
Constructs a TwigEnvironment object and stores cache and storage internally.
Parameters
string $root: The app root.
\Drupal\Core\Cache\CacheBackendInterface $cache: The cache bin.
string $twig_extension_hash: The Twig extension hash.
\Twig_LoaderInterface $loader: The Twig loader or loader chain.
array $options: The options for the Twig environment.
Overrides Twig_Environment::__construct
File
- core/lib/Drupal/Core/Template/TwigEnvironment.php, line 40
Class
- TwigEnvironment
- A class that defines a Twig environment for Drupal.
Namespace
Drupal\Core\Template
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | public function __construct( $root , CacheBackendInterface $cache , $twig_extension_hash , \Twig_LoaderInterface $loader = NULL, $options = array ()) { // Ensure that twig.engine is loaded, given that it is needed to render a // template because functions like TwigExtension::escapeFilter() are called. require_once $root . '/core/themes/engines/twig/twig.engine' ; $this ->templateClasses = array (); $options += array ( // @todo Ensure garbage collection of expired files. 'cache' => TRUE, 'debug' => FALSE, 'auto_reload' => NULL, ); // Ensure autoescaping is always on. $options [ 'autoescape' ] = 'html' ; $policy = new TwigSandboxPolicy(); $sandbox = new \Twig_Extension_Sandbox( $policy , TRUE); $this ->addExtension( $sandbox ); if ( $options [ 'cache' ] === TRUE) { $options [ 'cache' ] = new TwigPhpStorageCache( $cache , $twig_extension_hash ); } $this ->loader = $loader ; parent::__construct( $this ->loader, $options ); } |
Please login to continue.