Make the twig environment.

@return \Autarky\TwigTemplating\TwigEnvironment
6367
public function makeTwigEnvironment(ContainerInterface $dic)
	{
		$config = $this->app->getConfig();
		$options = ['debug' => $config->get('app.debug')];

		if ($config->has('path.templates_cache')) {
			$options['cache'] = $config->get('path.templates_cache');
		} else if ($config->has('path.storage')) {
			$options['cache'] = $config->get('path.storage').'/twig';
		}

		$env = new TwigEnvironment($dic->resolve('Twig_LoaderInterface'), $options);

		// merge core framework extensions with user extensions
		$extensions = array_merge([
			'Autarky\TwigTemplating\Extensions\PartialExtension',
			'Autarky\TwigTemplating\Extensions\UrlGenerationExtension' =>
				['Autarky\Routing\UrlGenerator'],
			'Autarky\TwigTemplating\Extensions\SessionExtension' =>
				['Symfony\Component\HttpFoundation\Session\Session'],
		], $this->app->getConfig()->get('twig.extensions', []));

		// iterate through the array of extensions. if the array key is an
		// integer, there are no dependencies defined for that extension and we
		// can simply add it. if the array key is a string, the key is the class
		// name of the extension and the value is an array of class dependencies
		// that must be bound to the service container in order for the
		// extension to be loaded.
		foreach ($extensions as $extension => $dependencies) {
			if (is_int($extension)) {
				$env->addExtension($dic->resolve($dependencies));
			} else {
				foreach ((array) $dependencies as $dependency) {
					if (!$dic->isBound($dependency)) {
						// break out of this inner foreach loop and continue to
						// the next iteration of the outer foreach loop,
						// effectively preventing the extension from loading
						continue 2;
					}
				}

				// if any of the dependencies are not met in the above loop,
				// this line of code will not be executed
				$env->addExtension($dic->resolve($extension));
			}
		}

		return $env;
	}
59422
protected function createApplication()
    {
        putenv('APP_ENV=' . $this->getEnv());

        $app = require $this->appPath;

        $app->make(Kernel::class)->bootstrap();

        Carbon::setTestNow(Carbon::now());

        return $app;
    }
161521
public function setupTwig()
	{
		$twigLoader = new TwigLoader($this->viewManager);
		$config = [];

		if ($this->viewManager->cachePath)
		{
			$config['cache'] = $this->viewManager->cachePath.'twig/';
		}

		$this->twig = new Twig_Environment($twigLoader, $config);
	}
1286238
public function getInstance()
    {
        if (!$this->parserInstance) {
            /**
             * Check if Twig_Autoloader class exists
             * otherwise include it.
             */
        
            if (!class_exists('\Twig_Autoloader')) {
                require_once $this->parserDirectory . '/Autoloader.php';
            }

            \Twig_Autoloader::register();
            $loader = new \Twig_Loader_Filesystem($this->getTemplateDirs());
            $this->parserInstance = new \Twig_Environment(
                $loader,
                $this->parserOptions
            );

            foreach ($this->parserExtensions as $ext) {
                $extension = is_object($ext) ? $ext : new $ext;
                $this->parserInstance->addExtension($extension);
            }
        }

        return $this->parserInstance;
    }
203894
public function getConfigTreeBuilder()
    {
        $builder = new TreeBuilder();
        $twig    = $builder->root('twig');
        {
            $twig->children()->scalarNode('template_dir');
            $twig->children()->scalarNode('cache_dir')->defaultValue(null);
            $twig->children()->scalarNode('asset_base')->defaultValue('');
            $twig->children()->variableNode('globals')->defaultValue([]);
        }

        return $builder;
    }
1099141
public static function make()
    {
        $resolver = new TemplateResolver();

        $services = Provider::getServices();
        $config   = $services->get('Config');

        if (isset($config['error']['html']['templates'])) {
            $templates = (array) $config['error']['html']['templates'];
            foreach ($templates as $template => $path) {
                $resolver->setTemplate($template, $path);
            }
        }

        return $resolver;
    }
744951
public function registerTwigEngine()
    {
        /** @var Factory $factory */
        $factory = $this->app['view'];
        $factory->addExtension('twig', 'twig', function () {
            return new Twig($this->app['twig'], $this->app['view.finder']);
        });
    }
1108112
public function registerTwig()
    {
        \Twig_Autoloader::register();

        $loader = new \Twig_Loader_Filesystem($_SERVER['DOCUMENT_ROOT'].'/../src/' . $this->app->getProjectName() . '/View');

        $twig = new \Twig_Environment($loader, array(
            'cache'       => $_SERVER['DOCUMENT_ROOT'].'/../app/cache/twig',
            'auto_reload' => true
        ));

        return $twig;
    }
658018
public function getTwig()
	{
		
		if (!$this->twig)
		{
			$loader = new \Twig_Loader_Filesystem( $this->getTemplateDir().'/'.TWIG_TEMPLATES_PATH, getcwd() );
			
			if (file_exists($this->getTemplateDir().'/widgets'))
				$loader->addPath( $this->getTemplateDir().'/widgets' ,'widget' );
			
			foreach ($this->_widgetPaths as $p) $loader->addPath( $p ,'widget' );			
			$loader->addPath( CMSROOT.'/widgets' ,'widget' );
			
			foreach ($this->_widgetPaths as $p) $loader->addPath( $p ,'widget_distrib' );			
			$loader->addPath( CMSROOT.'/widgets' ,'widget_distrib' );			
			
			$options = array(
				'cache'       => TWIG_CACHE_DIR,
				'auto_reload' => true,
				'strict_variables' => true,
			);
			
			if ($this->debugMode) {
				$options['cache'] = false;
				$options['debug'] = true;
			}
			
			$this->twig = new \Twig_Environment($loader, $options);

			$this->twig->addTokenParser( new Twig\TokenParser\Widget() );
			$this->twig->addExtension( new \Twig_Extensions_Extension_Text() );	
			$this->twig->addExtension(new \Twig_Extensions_Extension_I18n());
			$this->twig->addExtension(new \Twig_Extension_Debug());

			$this->twig->addFunction(new \Twig_SimpleFunction('_', function($text) {
				return Application::getInstance()->getTranslator()->_($text);
			}));
			
			$this->twig->addFilter( new \Twig_SimpleFilter('phone', function($num) {
				
				return preg_replace('/[^\+^\d]/i','', $num);
				
			} ) );
			
			$this->twig->addGlobal('application', $this);
			$this->twig->addGlobal('t', $this->getTranslator());
			$this->twig->addGlobal('s',  $_SERVER);
			
		}
		
		return $this->twig;
		
	}
525477
protected function getTwig()
    {
        if (null === $this->twig) {
            $this->twig = new \Twig_Environment(new \Twig_Loader_Filesystem(self::TEMPLATE_DIR), [
                'debug'            => true,
                'cache'            => false,
                'strict_variables' => true,
                'autoescape'       => false,
            ]);

            $this->twig->addExtension(new StringExtension());

            $class = sprintf(
                '\Gdbots\Pbjc\Generator\Twig\%sGeneratorExtension',
                StringUtils::toCamelFromSlug(static::LANGUAGE)
            );

            $this->twig->addExtension(new $class($this->compileOptions, $this));
        }

        return $this->twig;
    }
61266
protected function getTwigEnvironment()
    {
        $twigEnvironment = new \Twig_Environment(new \Twig_Loader_Filesystem($this->skeletonDirs), array(
            'debug'            => true,
            'cache'            => false,
            'strict_variables' => true,
            'autoescape'       => false,
        ));

        $twigEnvironment->addExtension($this->container->get('twig.extension.text_formatter'));

        return $twigEnvironment;
    }
1207245
public function makeRelative() {
    $this->cygwin = FALSE;
    $this->wrapper = NULL;
    $this->prefix = NULL;
    return $this;
  }
780071
protected function createTwigLintCommand() {
    $twig = new Environment(new FilesystemLoader());

    $repo_root = $this->getConfigValue('repo.root');
    $extension_file_contents = file_get_contents($repo_root . '/docroot/core/lib/Drupal/Core/Template/TwigExtension.php');

    // Get any custom defined Twig filters to be ignored by linter.
    $twig_filters = (array) $this->getConfigValue('validate.twig.filters');

    // Add Twig filters from Drupal TwigExtension to be ignored.
    $drupal_filters = [];
    if ($matches_count = preg_match_all("#new \\\\Twig_SimpleFilter\('([^']+)',#", $extension_file_contents, $matches)) {
      $drupal_filters = $matches[1];
    }
    $twig_filters = array_merge($twig_filters, $drupal_filters);
    foreach ($twig_filters as $filter) {
      // Add two default arguments and set to variadic so that filters with
      // named arguments will be whitelisted.
      // @see \TwigNode_Expression_Call::getArguments
      // @see \TwigNode_Expression_Call::call()
      $twig->addFilter(new \Twig_SimpleFilter($filter, function ($node = '', array $args = []) {}, [
        'is_variadic' => TRUE,
      ]));
    }

    // Get any custom defined Twig functions to be ignored by linter.
    $twig_functions = (array) $this->getConfigValue('validate.twig.functions');

    // Add Twig functions from Drupal TwigExtension to be ignored.
    $drupal_functions = [];
    if ($matches_count = preg_match_all("#new \\\\Twig_SimpleFunction\('([^']+)',#", $extension_file_contents, $matches)) {
      $drupal_functions = $matches[1];
    }
    $twig_functions = array_merge($twig_functions, $drupal_functions);
    foreach ($twig_functions as $function) {
      // Add default argument and set to variadic so that functions with named
      // arguments will be whitelisted.
      // @see \TwigNode_Expression_Call::getArguments
      // @see \TwigNode_Expression_Call::call()
      $twig->addFunction(new \Twig_SimpleFunction($function, function (array $args = []) {}, [
        'is_variadic' => TRUE,
      ]));
    }

    // Add Drupal Twig parser to include trans tag.
    $token_parser_filename = $repo_root . '/docroot/core/lib/Drupal/Core/Template/TwigTransTokenParser.php';
    if (file_exists($token_parser_filename)) {
      require_once $token_parser_filename;
      $twig->addTokenParser(new TwigTransTokenParser());
    }

    $command = new TwigLintCommand();
    $command->setTwigEnvironment($twig);

    return $command;
  }
647800
public function rawOnEnvironment()
    {
        $environments = array_flatten(func_get_args());

        if (in_array($this->appEnvironment, $environments))
        {
            return $this->raw();
        }

        return $this;
    }
1162792
public function addTwigAssets()
    {
        if (!$this->twig instanceof \Twig_Environment) {
            throw new \LogicException('Twig environment not set');
        }
        $finder     = new Finder();
        $viewfinder = $this->viewfinder;
        if (count($viewfinder->getPaths()) > 0) {
            $iterator = $finder->files()->in($viewfinder->getPaths());
            foreach ($iterator as $file) {
                $resource = new TwigResource($this->loader, $file->getRelativePathname());
                $this->lam->addResource($resource, 'twig');
            }
        }
    }
362532
public function getTwig()
    {
        if ($this->_twig === null) {
            $this->_twig = new \Twig_Environment(new \Twig_Loader_Array());
        }

        return $this->_twig;
    }
605040
private function getEnvironment()
    {
        $paths         = $this->config->paths;
        $paths['root'] = $this->root;
        return new \Taniko\Saori\Generator\Environment(
            $this->getMaker(),
            $this->getTwigEnv("{$this->theme_dir}/twig"),
            $paths
        );
    }