You are here

public function Twig_Environment::__construct in Translation template extractor 6.3

Same name and namespace in other branches
  1. 7.3 vendor/Twig/Environment.php \Twig_Environment::__construct()

Constructor.

Available options:

  • debug: When set to true, it automatically set "auto_reload" to true as well (default to false).
  • charset: The charset used by the templates (default to UTF-8).
  • base_template_class: The base template class to use for generated templates (default to Twig_Template).
  • cache: An absolute path where to store the compiled templates, or false to disable compilation cache (default).
  • auto_reload: Whether to reload the template if the original source changed. If you don't provide the auto_reload option, it will be determined automatically based on the debug value.
  • strict_variables: Whether to ignore invalid variables in templates (default to false).
  • autoescape: Whether to enable auto-escaping (default to html):

    • false: disable auto-escaping
    • true: equivalent to html
    • html, js: set the autoescaping to one of the supported strategies
    • PHP callback: a PHP callback that returns an escaping strategy based on the template "filename"
  • optimizations: A flag that indicates which optimizations to apply (default to -1 which means that all optimizations are enabled; set it to 0 to disable).

Parameters

Twig_LoaderInterface $loader A Twig_LoaderInterface instance:

array $options An array of options:

File

vendor/Twig/Environment.php, line 84

Class

Twig_Environment
Stores the Twig configuration.

Code

public function __construct(Twig_LoaderInterface $loader = null, $options = array()) {
  if (null !== $loader) {
    $this
      ->setLoader($loader);
  }
  $options = array_merge(array(
    'debug' => false,
    'charset' => 'UTF-8',
    'base_template_class' => 'Twig_Template',
    'strict_variables' => false,
    'autoescape' => 'html',
    'cache' => false,
    'auto_reload' => null,
    'optimizations' => -1,
  ), $options);
  $this->debug = (bool) $options['debug'];
  $this->charset = strtoupper($options['charset']);
  $this->baseTemplateClass = $options['base_template_class'];
  $this->autoReload = null === $options['auto_reload'] ? $this->debug : (bool) $options['auto_reload'];
  $this->strictVariables = (bool) $options['strict_variables'];
  $this->runtimeInitialized = false;
  $this
    ->setCache($options['cache']);
  $this->functionCallbacks = array();
  $this->filterCallbacks = array();
  $this
    ->addExtension(new Twig_Extension_Core());
  $this
    ->addExtension(new Twig_Extension_Escaper($options['autoescape']));
  $this
    ->addExtension(new Twig_Extension_Optimizer($options['optimizations']));
  $this->extensionInitialized = false;
  $this->staging = new Twig_Extension_Staging();
}