public function Twig_Environment::__construct in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/twig/twig/lib/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, a Twig_Cache_Interface implementation, 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
- filename: set the autoescaping strategy based on the template filename extension
- 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/ twig/ lib/ Twig/ Environment.php, line 91
Class
- Twig_Environment
- Stores the Twig configuration.
Code
public function __construct(Twig_LoaderInterface $loader = null, $options = array()) {
if (null !== $loader) {
$this
->setLoader($loader);
}
else {
@trigger_error('Not passing a Twig_LoaderInterface as the first constructor argument of Twig_Environment is deprecated.', E_USER_DEPRECATED);
}
$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
->setCache($options['cache']);
$this
->addExtension(new Twig_Extension_Core());
$this
->addExtension(new Twig_Extension_Escaper($options['autoescape']));
$this
->addExtension(new Twig_Extension_Optimizer($options['optimizations']));
$this->staging = new Twig_Extension_Staging();
// For BC
if (is_string($this->originalCache)) {
$r = new ReflectionMethod($this, 'writeCacheFile');
if ($r
->getDeclaringClass()
->getName() !== __CLASS__) {
@trigger_error('The Twig_Environment::writeCacheFile method is deprecated and will be removed in Twig 2.0.', E_USER_DEPRECATED);
$this->bcWriteCacheFile = true;
}
$r = new ReflectionMethod($this, 'getCacheFilename');
if ($r
->getDeclaringClass()
->getName() !== __CLASS__) {
@trigger_error('The Twig_Environment::getCacheFilename method is deprecated and will be removed in Twig 2.0.', E_USER_DEPRECATED);
$this->bcGetCacheFilename = true;
}
}
}