public function TwigEnvironment::__construct in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Template/TwigEnvironment.php \Drupal\Core\Template\TwigEnvironment::__construct()
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.
File
- core/lib/ Drupal/ Core/ Template/ TwigEnvironment.php, line 45 
- Contains \Drupal\Core\Template\TwigEnvironment.
Class
- TwigEnvironment
- A class that defines a Twig environment for Drupal.
Namespace
Drupal\Core\TemplateCode
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);
}