yii\twig\ViewRenderer::init PHP Method

init() public method

public init ( )
    public function init()
    {
        $this->twig = new \Twig_Environment(null, array_merge(['cache' => Yii::getAlias($this->cachePath), 'charset' => Yii::$app->charset], $this->options));
        $this->twig->setBaseTemplateClass('yii\\twig\\Template');
        // Adding custom globals (objects or static classes)
        if (!empty($this->globals)) {
            $this->addGlobals($this->globals);
        }
        // Adding custom functions
        if (!empty($this->functions)) {
            $this->addFunctions($this->functions);
        }
        // Adding custom filters
        if (!empty($this->filters)) {
            $this->addFilters($this->filters);
        }
        $this->addExtensions([new Extension($this->uses)]);
        // Adding custom extensions
        if (!empty($this->extensions)) {
            $this->addExtensions($this->extensions);
        }
        $this->twig->addGlobal('app', \Yii::$app);
        // Change lexer syntax (must be set after other settings)
        if (!empty($this->lexerOptions)) {
            $this->setLexerOptions($this->lexerOptions);
        }
    }