__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). * autoescape: Whether to enable auto-escaping (default to true); * 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)
public __construct ( Twig_LoaderInterface $loader = null, array $options = [] )
$loader Twig_LoaderInterface A Twig_LoaderInterface instance
$options array An array of options
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));
     }
 }
Example #2
0
 public function __construct(Zwig_View $view, Twig_LoaderInterface $loader = null, $options = array(), Twig_LexerInterface $lexer = null, Twig_ParserInterface $parser = null, Twig_CompilerInterface $compiler = null)
 {
     $parser = $parser !== null ? $parser : new Zwig_Parser();
     parent::__construct($loader, $options, $lexer, $parser, $compiler);
     $this->addExtension(new Zwig_Extension());
     $this->view = $view;
 }
Example #3
0
 /**
  * Constructs a TwigEnvironment object and stores cache and storage
  * internally.
  */
 public function __construct(\Twig_LoaderInterface $loader = NULL, $options = array(), ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler)
 {
     // @todo Pass as arguments from the DIC.
     $this->cache_object = \Drupal::cache();
     // Ensure that twig.engine is loaded, given that it is needed to render a
     // template because functions like twig_drupal_escape_filter are called.
     require_once DRUPAL_ROOT . '/core/themes/engines/twig/twig.engine';
     // Set twig path namespace for themes and modules.
     $namespaces = array();
     foreach ($module_handler->getModuleList() as $name => $extension) {
         $namespaces[$name] = $extension->getPath();
     }
     foreach ($theme_handler->listInfo() as $name => $extension) {
         $namespaces[$name] = $extension->getPath();
     }
     foreach ($namespaces as $name => $path) {
         $templatesDirectory = $path . '/templates';
         if (file_exists($templatesDirectory)) {
             $loader->addPath($templatesDirectory, $name);
         }
     }
     $this->templateClasses = array();
     $this->stringLoader = new \Twig_Loader_String();
     parent::__construct($loader, $options);
 }
 public function __construct($config, $app, $translator_service, $csrf_provider_service = null)
 {
     $this->translator_service = $translator_service;
     $this->csrf_provider_service = $csrf_provider_service;
     $this->app = $app;
     $this->context_transformers = isset($config['context_transformers']) && is_array($config['context_transformers']) ? $config['context_transformers'] : array();
     $cache_disabled = isset($config['debug']) ? $config['debug'] : false;
     $cache_path = isset($config['cache_path']) ? $config['cache_path'] : null;
     $paths = isset($config['paths']) ? $config['paths'] : array();
     if (!$cache_disabled && !file_exists($cache_path)) {
         mkdir($cache_path, 0777, true);
     }
     $_config = array();
     if (!$cache_disabled && file_exists($cache_path)) {
         $_config['cache'] = $config['cache_path'];
     }
     $loader = new \Twig_Loader_Filesystem($paths);
     parent::__construct($loader, $_config);
     // setup forms if form service is available in the app
     $this->initialiseExtensions($config);
     $this->addGlobal('app', $app);
     $this->addExtension(new TwigCoreExtension());
     if (class_exists('Symfony\\Bridge\\Twig\\Extension\\RoutingExtension')) {
         if (isset($app['url_generator'])) {
             $this->addExtension(new RoutingExtension($app['url_generator']));
         }
     }
     // setup filters defined in config
     if (isset($config['filters'])) {
         foreach ($config['filters'] as $name => $filter_config) {
             $filter = $filter_config['function'];
             if (!is_string($filter)) {
                 try {
                     $function = Utils::getClosure($filter);
                 } catch (InvalidClassMethodException $e) {
                     // noop: treat as native php function
                 }
             }
             $options = isset($function_config['options']) ? $function_config['options'] : array();
             $filter = new \Twig_SimpleFilter($name, $filter, $options);
             $this->addFilter($filter);
         }
     }
     // setup functions defined in config
     if (isset($config['functions'])) {
         foreach ($config['functions'] as $name => $function_config) {
             $function = $function_config['function'];
             if (!is_string($function)) {
                 try {
                     $function = Utils::getClosure($function);
                 } catch (InvalidClassMethodException $e) {
                     // noop: treat as native php function
                 }
             }
             $options = isset($function_config['options']) ? $function_config['options'] : array();
             $function = new \Twig_SimpleFunction($name, $function, $options);
             $this->addFunction($function);
         }
     }
 }
Example #5
0
 /**
  * @param Container $c
  * @param \Twig_LoaderInterface $twig_loader
  */
 public function __construct(Container $c, \Twig_LoaderInterface $twig_loader = null)
 {
     if (empty($twig_loader)) {
         $twig_loader = new \Twig_Loader_Filesystem($c['template_params']['paths']);
     }
     parent::__construct($twig_loader, $c['template_params']);
     $this->setConfig($c);
 }
 /**
  * Constructor.
  *
  * @param Twig_LoaderInterface $loader  A Twig_LoaderInterface instance
  * @param array                $options An array of options
  */
 public function __construct(\Twig_LoaderInterface $loader = null, $options = [])
 {
     parent::__construct($loader, $options);
     $this->shortcodeCallbacks = [];
     $this->shortcodeFilterCallbacks = [];
     // Overwrite internal staging class
     $this->staging = new Staging();
 }
Example #7
0
 public function __construct(\Twig_LoaderInterface $loader, BaseReport $report, ReportTemplatingHelper $templatingHelper, $options = array())
 {
     parent::__construct($loader, $options);
     $this->report = $report;
     $this->extensionManager = new RenderEngineExtensionManager($templatingHelper, $report);
     $this->templatingHelper = $templatingHelper;
     $this->registerExtensions();
 }
Example #8
0
 /**
  * {@inheritDoc}
  */
 public function __construct(Twig_LoaderInterface $loader = null, $options = array())
 {
     parent::__construct($loader, $options);
     $this->addExtension(new StubbedCore());
     $this->initExtensions();
     $broker = new StubbedTokenParserBroker();
     $this->parsers->addTokenParserBroker($broker);
 }
Example #9
0
 public function __construct(\Twig_LoaderInterface $loader = null, $options = [])
 {
     if (DEBUG) {
         $options = array_merge($options, ['debug' => true]);
     }
     parent::__construct($loader, $options);
     $this->addExtension(new Twig_Extension_Debug());
     $this->helpers = new ViewHelpers();
 }
Example #10
0
 /**
  * Constructor
  *
  * @param \src\config\config $src_config The src configuration
  * @param \src\path_helper $path_helper src path helper
  * @param \src\extension\manager $extension_manager src extension manager
  * @param \Twig_LoaderInterface $loader Twig loader interface
  * @param array $options Array of options to pass to Twig
  */
 public function __construct($src_config, \src\path_helper $path_helper, \src\extension\manager $extension_manager = null, \Twig_LoaderInterface $loader = null, $options = array())
 {
     $this->src_config = $src_config;
     $this->src_path_helper = $path_helper;
     $this->extension_manager = $extension_manager;
     $this->src_root_path = $this->src_path_helper->get_src_root_path();
     $this->web_root_path = $this->src_path_helper->get_web_root_path();
     return parent::__construct($loader, $options);
 }
 /**
  * {@inheritdoc}
  */
 public function __construct(Twig_LoaderInterface $loader, array $options = array())
 {
     parent::__construct($loader, $options);
     if (isset($options['sf_context']) && $options['sf_context'] instanceof sfContext) {
         $this->context = $options['sf_context'];
     } else {
         $this->context = sfContext::getInstance();
     }
 }
 public function __construct()
 {
     parent::__construct(new Kwf_View_Twig_FilesystemLoader('.'), array('cache' => 'cache/twig', 'auto_reload' => false));
     $this->addFilter(new Twig_SimpleFilter('date', array('Kwf_Component_Renderer_Twig_Environment', 'date'), array('needs_context' => true)));
     $this->addFilter(new Twig_SimpleFilter('dateTime', array('Kwf_Component_Renderer_Twig_Environment', 'dateTime'), array('needs_context' => true)));
     $this->addFilter(new Twig_SimpleFilter('money', array('Kwf_Component_Renderer_Twig_Environment', 'money'), array('needs_context' => true)));
     $this->addFilter(new Twig_SimpleFilter('mailEncodeText', array('Kwf_Component_Renderer_Twig_Environment', 'mailEncodeText')));
     $this->addFilter(new Twig_SimpleFilter('mailLink', array('Kwf_Component_Renderer_Twig_Environment', 'mailLink')));
     $this->addFilter(new Twig_SimpleFilter('hiddenOptions', array('Kwf_Component_Renderer_Twig_Environment', 'hiddenOptions')));
 }
Example #13
0
 public function __construct(Twig_LoaderInterface $loader = NULL, $options = array())
 {
     $this->fileExtension = twig_extension();
     $options = array_merge(array('autorender' => TRUE), $options);
     // Auto render means, overrule default class
     if ($options['autorender']) {
         $this->autoRender = TRUE;
     }
     parent::__construct($loader, $options);
 }
 /**
  * Twig engine constructor
  */
 public function __construct()
 {
     $primerLoader = new Loader();
     // Setup the loader to look from the base directory
     $fileSystemLoader = new \Twig_Loader_Filesystem([Primer::$PATTERN_PATH, Primer::$VIEW_PATH, Primer::$BASE_PATH]);
     $loader = new \Twig_Loader_Chain([$fileSystemLoader, $primerLoader]);
     // Create the engine with the correct cache path and set it to
     // invalidate the cache when a template changes
     parent::__construct($loader, array('cache' => Primer::$CACHE_PATH, 'auto_reload' => true));
 }
 /**
  * @param \Twig_LoaderInterface   $loader
  * @param array                   $options
  * @param VariablesProvider       $variablesProvider
  * @param Cache                   $cache
  * @param                         $cacheKey
  * @param \Twig_Extension_Sandbox $sandbox
  * @param TranslatorInterface     $translator
  */
 public function __construct(\Twig_LoaderInterface $loader, $options, VariablesProvider $variablesProvider, Cache $cache, $cacheKey, \Twig_Extension_Sandbox $sandbox, TranslatorInterface $translator)
 {
     parent::__construct($loader, $options);
     $this->variablesProvider = $variablesProvider;
     $this->sandBoxConfigCache = $cache;
     $this->cacheKey = $cacheKey;
     $this->addExtension($sandbox);
     $this->configureSandbox();
     $this->translator = $translator;
 }
 public function __construct(\Twig_LoaderInterface $loader, $options, ConfigProvider $configProvider, Cache $cache, $cacheKey, SecurityContextInterface $securityContext, \Twig_Extension_Sandbox $sandbox)
 {
     parent::__construct($loader, $options);
     $this->configProvider = $configProvider;
     $this->sandBoxConfigCache = $cache;
     $this->cacheKey = $cacheKey;
     $this->user = $securityContext->getToken() && !is_string($securityContext->getToken()->getUser()) ? $securityContext->getToken()->getUser() : false;
     $this->addExtension($sandbox);
     $this->configureSandbox();
 }
 /**
  * @param Twig_Loader_File $loader
  */
 public function __construct($loader)
 {
     parent::__construct($loader);
     $this->global_functions = array('esc_url', '__', 'esc_html', 'esc_attr', 'esc_textarea', 'urlencode', 'esc_url_raw', '_n', 'home_url', 'sanitize_html_class', 'hw_option', 'hw__post', 'hw__get', 'hw__req', '_hw_global');
     foreach ($this->global_functions as $func) {
         if (function_exists($func)) {
             $this->addFunction($func, new Twig_Function_Function($func));
         }
     }
     $this->addFunction('_staticCall', new Twig_Function_Function(array($this, 'staticCall')));
 }
Example #18
0
 public function __construct(\Twig_LoaderInterface $loader = NULL, $options = array(), $ci = NULL, $extensions = array())
 {
     parent::__construct($loader, $options);
     $this->CI = $ci == NULL ? get_instance() : $ci;
     $this->_extensions = $extensions;
     if (isset($options['debug']) && $options['debug']) {
         $this->addExtension(new \Twig_Extension_Debug());
     }
     $this->assetsDir = rtrim('', DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR;
     $this->assetFactory = new AssetFactory($this->assetsDir, $this->isDebug());
     $this->initCustomExtensions();
 }
Example #19
0
 /**
  * Constructor
  *
  * @param \phpbb\config\config $phpbb_config The phpBB configuration
  * @param \phpbb\filesystem\filesystem $filesystem
  * @param \phpbb\path_helper $path_helper phpBB path helper
  * @param \Symfony\Component\DependencyInjection\ContainerInterface $container The dependency injection container
  * @param string $cache_path The path to the cache directory
  * @param \phpbb\extension\manager $extension_manager phpBB extension manager
  * @param \Twig_LoaderInterface $loader Twig loader interface
  * @param array $options Array of options to pass to Twig
  */
 public function __construct(\phpbb\config\config $phpbb_config, \phpbb\filesystem\filesystem $filesystem, \phpbb\path_helper $path_helper, \Symfony\Component\DependencyInjection\ContainerInterface $container, $cache_path, \phpbb\extension\manager $extension_manager = null, \Twig_LoaderInterface $loader = null, $options = array())
 {
     $this->phpbb_config = $phpbb_config;
     $this->filesystem = $filesystem;
     $this->phpbb_path_helper = $path_helper;
     $this->extension_manager = $extension_manager;
     $this->container = $container;
     $this->phpbb_root_path = $this->phpbb_path_helper->get_phpbb_root_path();
     $this->web_root_path = $this->phpbb_path_helper->get_web_root_path();
     $options = array_merge(array('cache' => defined('IN_INSTALL') ? false : $cache_path, 'debug' => false, 'auto_reload' => (bool) $this->phpbb_config['load_tplcompile'], 'autoescape' => false), $options);
     return parent::__construct($loader, $options);
 }
Example #20
0
 public function __construct(\Twig_LoaderInterface $loader, BaseReport $report, $options = array(), RenderEngineExtensionManager $extensionManager)
 {
     parent::__construct($loader, $options);
     $this->report = $report;
     $this->extensionManager = $extensionManager;
     $this->extensionManager->setReport($report);
     $this->router = $this->extensionManager->findExtension('report_routing');
     if (null === $this->router) {
         throw new ExtensionNotLoadedException('report_routing');
     }
     $this->registerExtensions();
 }
Example #21
0
 /**
  * Constructs a TwigEnvironment object and stores cache and storage
  * internally.
  *
  * @param string $root
  *   The app root.
  * @param \Drupal\Core\Cache\CacheBackendInterface $cache
  *   The cache bin.
  * @param \Twig_LoaderInterface $loader
  *   The Twig loader or loader chain.
  * @param array $options
  *   The options for the Twig environment.
  */
 public function __construct($root, CacheBackendInterface $cache, \Twig_LoaderInterface $loader = NULL, $options = array())
 {
     $this->cache_object = $cache;
     // Ensure that twig.engine is loaded, given that it is needed to render a
     // template because functions like TwigExtension::escapeFilter() are called.
     require_once $root . '/core/themes/engines/twig/twig.engine';
     $this->templateClasses = array();
     $options += array('cache' => TRUE, 'debug' => FALSE, 'auto_reload' => NULL);
     // Ensure autoescaping is always on.
     $options['autoescape'] = TRUE;
     $this->loader = $loader;
     parent::__construct($this->loader, $options);
 }
Example #22
0
 /**
  * Instantiate the renderer.
  *
  * @param   array  $config  The array of configuration parameters.
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function __construct($config = array())
 {
     // Merge the config.
     $this->config = array_merge($this->config, $config);
     // Set the templates location path.
     $this->setTemplatesPaths($this->config['templates_base_dir'], true);
     try {
         $this->twigLoader = new \Twig_Loader_Filesystem($this->templatesPaths);
     } catch (\Twig_Error_Loader $e) {
         throw new \RuntimeException($e->getRawMessage());
     }
     parent::__construct($this->twigLoader, $this->config['environment']);
 }
Example #23
0
 /**
  * Construct the \Twig_Environment.
  *
  *
  * @param null|\Twig_Loader_Filesystem|\Twig_Loader_Array $loader The loader in charge of finding twig 
  * templates.
  * @param null|string|array $options Either a relative string path to the twig configuration options, an array 
  * of configuration options, or null for no options.
  */
 public function __construct($loader = null, $options = 'app/config/twig.php')
 {
     if ($loader === null) {
         $loader = self::defaultLoader();
     }
     //if
     if ($options !== null && !is_array($options)) {
         $options = (require \App::path() . '/' . trim($options, '/'));
     }
     //if
     parent::__construct($loader, $options);
     $this->addExtension(new \Disco\twig\TwigExtension());
 }
Example #24
0
	public function __construct($templatePaths, array $options = array())
	{
		if(!is_array($templatePaths)) {
			$templatePaths = array($templatePaths);
		}

		$options['debug'] = GetConfig('DebugMode');

		$loader = new Twig_Loader_Filesystem($templatePaths);
		parent::__construct($loader, $options);
		$this->addExtension(new Interspire_Template_Extension());
		$this->addExtension(new Twig_Extension_Escaper());
	}
 /**
  * Constructs a TwigEnvironment object and stores cache and storage
  * internally.
  *
  * @param string $root
  *   The app root.
  * @param \Twig_LoaderInterface $loader
  *   The Twig loader or loader chain.
  * @param array $options
  *   The options for the Twig environment.
  */
 public function __construct($root, \Twig_LoaderInterface $loader = NULL, $options = array())
 {
     // @todo Pass as arguments from the DIC.
     $this->cache_object = \Drupal::cache();
     // Ensure that twig.engine is loaded, given that it is needed to render a
     // template because functions like twig_drupal_escape_filter are called.
     require_once $root . '/core/themes/engines/twig/twig.engine';
     $this->templateClasses = array();
     $options += array('cache' => TRUE, 'debug' => FALSE, 'auto_reload' => NULL);
     // Ensure autoescaping is always on.
     $options['autoescape'] = TRUE;
     $this->loader = $loader;
     parent::__construct($this->loader, $options);
 }
 public function __construct(\Twig_LoaderInterface $loader = null, $options = [])
 {
     if (!array_key_exists('autorender', $options)) {
         $options['autorender'] = true;
     }
     $this->autoRender = (bool) $options['autorender'];
     if ($this->autoRender) {
         // Sad but true story, the TFD7 implementation does filter calls
         // everywhere, while I would prefer to keep the autoescape for
         // security, I can't because all templates generated using the TFD
         // extension enabled will be *fully* escape (WTF, seriously)...
         $options['autoescape'] = false;
     }
     parent::__construct($loader, $options);
 }
Example #27
0
 public function __construct()
 {
     $this->_CI =& get_instance();
     $this->_CI->load->config("twig");
     $twigConfig = $this->_CI->config->item("twig");
     $loader = new Twig_Loader_Filesystem($twigConfig["directory_tempalte"]);
     parent::__construct($loader, $twigConfig);
     /* All functions you want add to twig */
     $this->addGlobal('base_url', base_url());
     $this->addGlobal('input', $this->_CI->input);
     $this->addGlobal('uri', $this->_CI->uri);
     foreach (get_defined_constants() as $key => $value) {
         $this->addGlobal($key, $value);
     }
 }
 public function __construct()
 {
     $config = array('cache' => 'cache/twig', 'auto_reload' => false);
     if (Kwf_Config::getValue('debug.twig')) {
         $config['debug'] = true;
     }
     parent::__construct(new Kwf_View_Twig_FilesystemLoader('.'), $config);
     if (isset($config['debug'])) {
         $this->addExtension(new Twig_Extension_Debug());
     }
     $this->addFilter(new Twig_SimpleFilter('date', array('Kwf_Component_Renderer_Twig_Environment', 'date'), array('needs_context' => true)));
     $this->addFilter(new Twig_SimpleFilter('dateTime', array('Kwf_Component_Renderer_Twig_Environment', 'dateTime'), array('needs_context' => true)));
     $this->addFilter(new Twig_SimpleFilter('money', array('Kwf_Component_Renderer_Twig_Environment', 'money'), array('needs_context' => true)));
     $this->addFilter(new Twig_SimpleFilter('mailEncodeText', array('Kwf_Component_Renderer_Twig_Environment', 'mailEncodeText')));
     $this->addFilter(new Twig_SimpleFilter('mailLink', array('Kwf_Component_Renderer_Twig_Environment', 'mailLink')));
     $this->addFilter(new Twig_SimpleFilter('hiddenOptions', array('Kwf_Component_Renderer_Twig_Environment', 'hiddenOptions')));
 }
Example #29
0
 public function __construct()
 {
     $this->CI =& get_instance();
     $this->loadConfig();
     $loader = new Twig_Loader_Filesystem($this->paths);
     parent::__construct($loader, $this->config);
     $this->addGlobal('environment', ENVIRONMENT);
     $this->addGlobal('ci_version', CI_VERSION);
     if ($this->config['benchmark']) {
         $this->addGlobal('elapsed_time', $this->CI->benchmark->elapsed_time('total_execution_time_start', 'total_execution_time_end'));
         $this->addGlobal('memory', round(memory_get_usage() / 1024 / 1024, 2) . 'MB');
     } else {
         // in case of usage
         $this->addGlobal('elapsed_time', 'null');
         $this->addGlobal('memory', 'null');
     }
 }
Example #30
0
 /**
  * Constructs a TwigEnvironment object and stores cache and storage
  * internally.
  *
  * @param string $root
  *   The app root.
  * @param \Drupal\Core\Cache\CacheBackendInterface $cache
  *   The cache bin.
  * @param string $twig_extension_hash
  *   The Twig extension hash.
  * @param \Twig_LoaderInterface $loader
  *   The Twig loader or loader chain.
  * @param array $options
  *   The options for the Twig environment.
  */
 public function __construct($root, CacheBackendInterface $cache, $twig_extension_hash, \Twig_LoaderInterface $loader = NULL, $options = array())
 {
     // Ensure that twig.engine is loaded, given that it is needed to render a
     // template because functions like TwigExtension::escapeFilter() are called.
     require_once $root . '/core/themes/engines/twig/twig.engine';
     $this->templateClasses = array();
     $options += array('cache' => TRUE, 'debug' => FALSE, 'auto_reload' => NULL);
     // Ensure autoescaping is always on.
     $options['autoescape'] = 'html';
     $policy = new TwigSandboxPolicy();
     $sandbox = new \Twig_Extension_Sandbox($policy, TRUE);
     $this->addExtension($sandbox);
     if ($options['cache'] === TRUE) {
         $options['cache'] = new TwigPhpStorageCache($cache, $twig_extension_hash);
     }
     $this->loader = $loader;
     parent::__construct($this->loader, $options);
 }