Get the user defined global for twig templates.

@return mixed
559514
protected function getUserDefinedGlobals()
    {
        if (file_exists(realpath(__DIR__.'/../../../../config/twig.php'))) {
            $this->config = require realpath(__DIR__.'/../../../../config/twig.php');
        } elseif (file_exists(realpath(__DIR__.'/../config/twig.php'))) {
            $this->config = require realpath(__DIR__.'/../config/twig.php');
        }

        return isset($this->config['twig_global']) ? $this->config['twig_global'] : [];
    }
590702
protected function loadTemplates()
	{
		$loader = new \Twig_Loader_Filesystem(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'templates');
		$this->twigEnv = new Twig_Environment($loader, ['cache' => false, 'debug' => true]);
		$this->twigEnv->addExtension(new Twig_Extension_Debug());

		// Custom filter for phpdoc
		$filter = new \Twig_Filter('phpdoc', function($string, $indentationCount = 0, $indentChar = "\t") {
			$result = str_repeat($indentChar, $indentationCount) . '/**' . "\n";
			// Split per line
			$lines = explode("\n", trim($string));
			foreach ($lines as $line) {
				$result .= str_repeat($indentChar, $indentationCount) . ' * ' . $line . "\n";
			}
			$result .= str_repeat($indentChar, $indentationCount) . ' */' . "\n";
			return $result;
		});

		$this->twigEnv->addFilter($filter);

		$this->managerTemplate = $this->twigEnv->load('manager.php.twig');
		$this->resourceTemplate = $this->twigEnv->load('resource.php.twig');
		$this->mainClientTemplate = $this->twigEnv->load('mainClient.php.twig');
		$this->mainExceptionTemplate = $this->twigEnv->load('mainException.php.twig');
		$this->unexpectedResponseExceptionTemplate = $this->twigEnv->load('unexpectedResponseException.php.twig');

		if (!is_null($this->testsOutputPath)) {
			$this->mainClientTestTemplate = $this->twigEnv->load('mainClientTest.php.twig');
			$this->managerTestTemplate = $this->twigEnv->load('managerTest.php.twig');
		}
	}
754047
public function actionGenerateAll()
    {
        $foundTemplates = $this->findTemplatesFiles();

        if (!$foundTemplates) {
            $this->notifyNoTemplatesFound();
            return static::EXIT_CODE_NORMAL;
        }

        if (!$this->confirmGeneration($foundTemplates)) {
            return static::EXIT_CODE_NORMAL;
        }

        $templatePath = Yii::getAlias($this->templatePath);
        $fixtureDataPath = Yii::getAlias($this->fixtureDataPath);

        FileHelper::createDirectory($fixtureDataPath);

        $generatedTemplates = [];

        foreach ($foundTemplates as $templateName) {
            $this->generateFixtureFile($templateName, $templatePath, $fixtureDataPath);            
            $generatedTemplates[] = $templateName;
        }

        $this->notifyTemplatesGenerated($generatedTemplates);
    }
166682
function &globals()
    {
        $globals = array();
        $packages = $this->packages(); // not by reference so as not to move the internal array pointer
        foreach ($packages as $name => $package) {
            $packageGlobals = $this->_packages[$name]->globals(); // not by reference so as not to move the internal array pointer
            if ($packageGlobals) {
                foreach ($packageGlobals as $key => $pack) {
                    $globals[$name.'.'.$key] =& $packageGlobals[$key];
                }
            }
        }
        ksort($globals);

        return $globals;
    }
1105992
public function getCode()
    {
        $locator = new TemplateLocator(new FileLocator($this->getTemplateDirs()));
        $templateNameParser = new TemplateNameParser();
        $loader = new FilesystemLoader($locator, $templateNameParser);
        $twig = new \Twig_Environment(
            $loader,
            array(
                'autoescape' => false,
                'strict_variables' => true,
                'debug' => true,
                'cache' => $this->getGenerator()->getTempDir(),
            )
        );

        $this->addTwigExtensions($twig, $loader);
        $this->addTwigFilters($twig);
        $template = $twig->loadTemplate($this->getTemplateName());

        $variables = $this->getVariables();
        $variables['builder'] = $this;

        return $template->render($variables);
    }
37919
public function getTemplates()
    {
        $template = parent::getTemplates();

        if ($default = $this->defaultTemplate) {
            $key = array_search('FormField', $template);

            if ($key !== false) {
                $default[$key] = $this->defaultTemplate;
            }
        }

        return $template;
    }
763760
public function getTemplate()
    {
        if ($this->expectedMessage) {
            return $this->getMessageTemplate();
        }

        if (!isset($this->template)) {
            return $this->getDefaultTemplate();
        }

        return $this->template;
    }
1212407
protected function getGlobal($name, $default = null)
    {
        return array_key_exists($name, $this->globals)?$this->globals[$name]:$default;
    }
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;
    }
993873
protected function getTemplate()
    {
        if ($this->template === null) {
            $this->template = \Tx_Oelib_TemplateRegistry::get(
                $this->templateFileName
            );
        }

        return $this->template;
    }
1176598
public function getTwig()
    {
        if (!$this->twig) {
            Twig_Autoloader::register();
            $this->twig_loader = new Twig_Loader_Filesystem($this->base_view_path);

            $this->twig = new Twig_Environment(
                $this->twig_loader,
                $this->loader_configs
            );
        }

        return $this->twig;
    }
1054989
public function getFunctions()
    {
        return [
            new \Twig_SimpleFunction(
                'variable',
                function ($group, $field) {
                    return $this->dispatch(new GetValuePresenter($group, $field));
                }
            ),
            new \Twig_SimpleFunction(
                'variable_value',
                function ($group, $field, $default = null) {
                    return $this->dispatch(new GetVariableValue($group, $field, $default));
                }
            ),
            new \Twig_SimpleFunction(
                'variable_group',
                function ($group) {
                    return (new Decorator())->decorate($this->dispatch(new GetVariableGroup($group)));
                }
            ),
        ];
    }
338550
public function getTemplate()
    {
        if (is_null($this->_template)) {
            $this->_template = new \Slick\Form\Template\SelectMultiple();
        }
        return $this->_template;
    }
163874
private function initTwig(){
        if($this->twig === null){
            $this->twig = new Environment(
                new FilesystemLoader(__DIR__ . "/../resource/views"),
                [
                    "debug" => true,
                ]
            );

            $this->twig->addExtension(
                new \Twig\Extension\DebugExtension
            );
            $this->twig->addExtension(
                new \Twig\Extension\StringLoaderExtension
            );
            $this->twig->addFilter(new \Twig_Filter("md5", function($v){
                return md5($v);
            }));
        }
    }
9775
private function getTwigEnvironment()
    {
        if (null == $this->twigEnvironment) {
            $this->twigEnvironment = $this->createTwigEnvironment();
        }
        return $this->twigEnvironment;
    }
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;
    }
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;
		
	}