Twig_Environment::__construct PHP Method

__construct() public method

Available options: * debug: When set to true, the generated templates have a __toString() method that you can use to display the generated nodes (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 is the original source changed. If you don't provide the auto_reload option, it will be determined automatically base on the debug value. * strict_variables: Whether to ignore invalid variables in templates (default to false).
public __construct ( Twig_LoaderInterface $loader = null, array $options = [], Twig_LexerInterface $lexer = null, Twig_ParserInterface $parser = null, Twig_CompilerInterface $compiler = null )
$loader Twig_LoaderInterface A Twig_LoaderInterface instance
$options array An array of options
$lexer Twig_LexerInterface A Twig_LexerInterface instance
$parser Twig_ParserInterface A Twig_ParserInterface instance
$compiler Twig_CompilerInterface A Twig_CompilerInterface instance
    public function __construct(Twig_LoaderInterface $loader = null, $options = array(), Twig_LexerInterface $lexer = null, Twig_ParserInterface $parser = null, Twig_CompilerInterface $compiler = null)
    {
        if (null !== $loader) {
            $this->setLoader($loader);
        }

        $this->setLexer(null !== $lexer ? $lexer : new Twig_Lexer());
        $this->setParser(null !== $parser ? $parser : new Twig_Parser());
        $this->setCompiler(null !== $compiler ? $compiler : new Twig_Compiler());

        $this->debug              = isset($options['debug']) ? (bool) $options['debug'] : false;
        $this->charset            = isset($options['charset']) ? $options['charset'] : 'UTF-8';
        $this->baseTemplateClass  = isset($options['base_template_class']) ? $options['base_template_class'] : 'Twig_Template';
        $this->autoReload         = isset($options['auto_reload']) ? (bool) $options['auto_reload'] : $this->debug;
        $this->extensions         = array('core' => new Twig_Extension_Core());
        $this->strictVariables    = isset($options['strict_variables']) ? (bool) $options['strict_variables'] : false;
        $this->runtimeInitialized = false;
        if (isset($options['cache']) && $options['cache']) {
            $this->setCache($options['cache']);
        }
    }

Same methods

Twig_Environment::__construct ( Twig_LoaderInterface $loader = null, array $options = [] )

Usage Example

Example #1
0
 public function __construct(ContainerInterface $container, \Twig_LoaderInterface $loader = null, $options = array())
 {
     parent::__construct($loader, $options);
     foreach ($container->findAnnotatedServiceIds('twig.extension') as $id => $attributes) {
         $this->addExtension($container->get($id));
     }
 }
All Usage Examples Of Twig_Environment::__construct