public function __construct($string) { \Twig_Autoloader::register(); $this->loader = new \Twig_Loader_String(); $this->twig = new \Twig_Environment($this->loader); $this->string = $string; /** * let twig know the BACBOX_URLBASE * templates need this information to correctly locate css, js and any other * static content from the webserver */ $this->_urlbase = BACBOX_URLBASE; /** * in case that multilanguage is enabled, we need to append the * language token to the urlbase for in-template links */ if (Registry::get('language_token')) { $this->_linkbase = BACBOX_URLBASE . Registry::get('language_token') . '/'; } else { $this->_linkbase = BACBOX_URLBASE; } // register the hostname for absolute linking $this->_hostname = Config::get('system.hostname'); $this->setHeader('Content-Type', 'text/html; charset="UTF-8"'); }
public function testAutoload() { $this->assertFalse(class_exists('FooBarFoo'), '->autoload() does not try to load classes that does not begin with Twig'); $autoloader = new Twig_Autoloader(); $this->assertTrue($autoloader->autoload('Twig_Parser'), '->autoload() returns true if it is able to load a class'); $this->assertFalse($autoloader->autoload('Foo'), '->autoload() returns false if it is not able to load a class'); }
/** * Constructor. * * @param IOInterface $io * @param TwigFactory $twigFactory * @param string $serverroot * @param string $documentroot * @param int $port * @param string $host */ public function __construct(IOInterface $io, $serverroot, $documentroot, $port, $host) { \Twig_Autoloader::register(); $this->io = $io; $this->port = $port; $this->host = $host; $this->serverroot = $serverroot; $this->documentroot = $documentroot; $this->buildTwig($serverroot); $this->requestHandler = new RequestHandler(function (Request $request) { $serverResponse = new ServerResponse(''); $serverRequest = new ServerRequest($request, $this->documentroot, $this->serverroot); try { $this->handleOnBeforeRequestFunction($serverRequest); $resourcePath = $serverRequest->getPathFilename(); if (file_exists($resourcePath) === true) { $serverResponse->setContent(file_get_contents($resourcePath)); $serverResponse->setContentType($serverRequest->getMimeType()); } else { $serverResponse->setStatusCode(404); $serverResponse->setContent($resourcePath); } $this->handleOnAfterRequestFunction($serverResponse); } catch (\Exception $e) { $serverResponse->setStatusCode(500); $serverResponse->setContent($e->getMessage()); } $this->logRequest($serverRequest->getIp(), $serverRequest->getPath(), $serverResponse->getStatusCode()); return $this->buildFinalResponse($serverResponse); }); $this->requestHandler->listen($port, $host)->enableHttpFoundationRequest(); }
/** * Constructor * * @param string $tmplPath * @param array $extraParams * @return void */ public function __construct($tmplPath = null, $extraParams = array()) { Twig_Autoloader::register(); $loader = new Twig_Loader_Filesystem($tmplPath); $cache_path = (array_key_exists('cache_path', $extraParams)) ? $extraParams['cache_path'] : '../cache' ; $view = new Twig_Environment($loader, array( 'cache' => $cache_path, 'auto_reload' => true, ) ); $escaper = new Twig_Extension_Escaper(true); $view->addExtension($escaper); $this->_twig = $view; if (null !== $tmplPath) { $this->setScriptPath($tmplPath); } foreach ($extraParams as $key => $value) { $this->_twig->{$key} = $value; } }
public function __construct() { if (!DEFINED("EXT")) { define("EXT", ".php"); } ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . APPPATH . 'third_party/Twig'); require_once (string) "Autoloader" . EXT; // Fire off the Twig register bootstrap function... Twig_Autoloader::register(); // Get CI instance $this->CI = get_instance(); // Load the Twig config file $this->CI->config->load('twig'); // Add in default Twig locations $this->add_template_location($this->CI->config->item('twig.locations')); // Get locations $this->_set_template_locations(); $this->_twig_loader = new Twig_Loader_Filesystem($this->_template_directories); // Get environment config settings $environment = $this->CI->config->item("twig.environment"); // Set our cache path or status $environment["cache"] = $environment["cache_status"] ? $environment["cache_location"] : FALSE; $twig_environment = array("cache" => $environment["cache"], "debug" => $environment["debug_mode"], "auto_reload" => $environment["auto_reload"], "autoescape" => $environment["autoescape"], "optimizations" => $environment["optimizations"]); $this->_twig = new Twig_Environment($this->_twig_loader, $twig_environment); if ($this->CI->config->item("twig.functions")) { foreach ($this->CI->config->item("twig.functions") as $function) { $this->register_function($function); } } if ($this->CI->config->item("twig.filters")) { foreach ($this->CI->config->item("twig.filters") as $filter) { $this->register_filter($filter); } } }
function __construct() { // This is how to call the template engine: // do_action('wunderground_render_template', $file_name, $data_array ); add_action('wunderground_render_template', array(&$this, 'render'), 10, 2); // Set up Twig Twig_Autoloader::register(); // This path should always be the last $base_path = trailingslashit(plugin_dir_path(Wunderground_Plugin::$file)) . 'templates'; $this->loader = new Twig_Loader_Filesystem($base_path); // Tap in here to add additional template paths $additional_paths = apply_filters('wunderground_template_paths', array(trailingslashit(get_stylesheet_directory()) . 'wunderground')); foreach ($additional_paths as $path) { // If the directory exists if (is_dir($path)) { // Tell Twig to use it first $this->loader->prependPath($path); } } // You can force debug mode by adding `add_filter( 'wunderground_twig_debug' '__return_true' );` $debug = apply_filters('wunderground_twig_debug', current_user_can('manage_options') && isset($_GET['debug'])); $this->twig = new Twig_Environment($this->loader, array('debug' => !empty($debug), 'auto_reload' => true)); if (!empty($debug)) { $this->twig->addExtension(new Twig_Extension_Debug()); } }
private function template() { $config = new Config($this->registry); $twigPath = $config->getTWIGPath(); $this->themeUrl = $this->registry->siteUrl . 'themes/' . $this->registry->template . '/'; $this->isAjaxRequest = $this->registry->dispatcher->isAjaxRequest(); require $twigPath; \Twig_Autoloader::register(); $loader = new \Twig_Loader_Filesystem($this->getTemplate()); $twig = new \Twig_Environment($loader); $urlFunction = new \Twig_SimpleFunction('url', function ($ctrl_action, $paramsArray = NULL) { $ctrl_action = explode('/', $ctrl_action); $controller = $ctrl_action[0] . '/'; $action = $ctrl_action[1] . '/'; $params = ''; if (isset($paramsArray)) { $params .= '?'; foreach ($paramsArray as $key => $value) { $params .= $key . '=' . $value; if (end($paramsArray) != $value) { $params .= '&'; } } } $url = $this->registry->siteUrl . $controller . $action . $params; return $url; }); $twig->addFunction($urlFunction); $template = $twig->loadTemplate($this->getView()); return $template; }
public function getTemplate($name) { Twig_Autoloader::register(); $loader = new Twig_Loader_Filesystem('app/templates'); $twig = new Twig_Environment($loader, []); return $twig->loadTemplate($name); }
public function init() { require_once APPPATH . 'classes/Twig/Autoloader.php'; Twig_Autoloader::register(); $this->config = array('templates_dir' => APPPATH . 'views/', 'cache_dir' => APPPATH . 'application/cache/twig/', 'cache_on' => false); $this->twig = new Twig_Environment(new Twig_Loader_String(), array('cache' => $this->config['cache_dir'], 'auto_reload' => !$this->config['cache_on'])); }
/** * Creates new TwigEnvironment if it doesn't already exist, and returns it. * * @return Twig_Environment */ public function getEnvironment() { if (!$this->twigEnvironment) { // Check for Composer Package Autoloader class loading if (!class_exists('Twig_Autoloader')) { require_once self::$twigDirectory . '/Autoloader.php'; } Twig_Autoloader::register(); $loader = new Twig_Loader_Filesystem($this->getTemplatesDirectory()); $this->twigEnvironment = new Twig_Environment($loader, self::$twigOptions); // Check for Composer Package Autoloader class loading if (!class_exists('Twig_Extensions_Autoloader')) { $extension_autoloader = dirname(__FILE__) . '/Extension/TwigAutoloader.php'; if (file_exists($extension_autoloader)) { require_once $extension_autoloader; } } if (class_exists('Twig_Extensions_Autoloader')) { Twig_Extensions_Autoloader::register(); foreach (self::$twigExtensions as $ext) { $this->twigEnvironment->addExtension(new $ext()); } } } return $this->twigEnvironment; }
public function __construct() { $this->model = new Model(); Twig_Autoloader::register(); $this->loader = new Twig_Loader_Filesystem('../templates/'); $this->twig = new Twig_Environment($this->loader); }
/** * Metodo Privado * Autoloader() * * Determina si ya fue incluida la libreria de twig * de lo contrario incluye la libreria correspondiente * @access private */ private function Autoloader() { if (class_exists('Twig_Autoloader') == false) { require implode(DIRECTORY_SEPARATOR, array(__SysNeuralFileRootProveedores__, 'Twig', 'Autoloader.php')); } Twig_Autoloader::register(); }
public function __construct($path = '') { if (empty($path)) { $path = $_SESSION['player']->getTemplatePath(); } // include and register Twig auto-loader if (!class_exists('Twig_Autoloader')) { include 'Twig/Autoloader.php'; } Twig_Autoloader::register(); try { // specify where to look for templates $loader = new Twig_Loader_Filesystem($path); // initialize Twig environment $this->twig = new Twig_Environment($loader, array('cache' => TEMPLATE_CACHE ? $path . 'cache' : false, 'auto_reload' => TEMPLATE_RELOAD, 'debug' => DEBUG)); } catch (Exception $e) { if (DEBUG) { die('ERROR: ' . $e->getMessage()); } else { die('ERROR: Template konnte nicht geladen werden!'); } } $this->twig->addFilter('ceil', new Twig_Filter_Function('ceil')); $this->vars = array(); $this->showRresource = true; }
public function view($page = 'home') { // if ( ! file_exists(APPPATH.'/views/templates/' . $page . '.twig')) // { // // Whoops, we don't have a page for that! // show_404(); // } $data['site_title'] = "SB Admin 2 - Bootstrap Admin Theme"; $data['title'] = ucfirst($page); // Capitalize the first letter $data['site_url'] = $this->config->site_url(); $data['stylesheets'] = $this->stylesheets(); $data['scripts'] = $this->scripts(); $data['footer_scripts'] = $this->footer_scripts(); $data['side_links'] = $this->sidemenu_links(); $data['meta'] = $this->meta_tags(); $data['cdns'] = $this->cdn_scripts(); $data['foo'] = 'This is cool!'; $data['bar'] = 'Twig + CodeIgniter rocks!'; require_once dirname(__DIR__) . '/third_party/twig/lib/Twig/Autoloader.php'; Twig_Autoloader::register(); $loader = new Twig_Loader_Filesystem(dirname(__DIR__) . '/views'); $twig = new Twig_Environment($loader); echo $twig->render('index.twig', $data); }
function __construct($debug = false) { $this->CI =& get_instance(); $this->CI->config->load('twig'); ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . APPPATH . 'libraries/Twig'); require_once (string) "Autoloader" . EXT; log_message('debug', "Twig Autoloader Loaded"); Twig_Autoloader::register(); if ($this->CI->router->fetch_module() != null) { $template_module_dir = APPPATH . 'modules/' . $this->CI->router->fetch_module() . '/views/'; $template_global_dir = $this->CI->config->item('template_dir'); $this->_template_dir = array($template_global_dir, $template_module_dir); $this->_cache_dir = $this->CI->config->item('cache_dir'); $loader = new Twig_Loader_Filesystem($this->_template_dir); $this->_twig = new Twig_Environment($loader, array('cache' => $this->_cache_dir, 'debug' => $debug)); $this->_twig->addGlobal("router", $this->CI->router); $this->_twig->addGlobal("session", $this->CI->session); $this->_twig->addGlobal("security", $this->CI->security); $this->_twig->addGlobal("input", $this->CI->input); $this->_twig->addGlobal("widget_system", $this->CI->widget_system); foreach (get_defined_functions() as $functions) { foreach ($functions as $function) { $this->_twig->addFunction($function, new Twig_Function_Function($function)); } } } else { show_404(); } }
public function __construct($templatePath) { \Twig_Autoloader::register(false); $loader = new \Twig_Loader_Filesystem($templatePath); $renderer = new \Twig_Environment($loader); $this->renderer = $renderer; }
public function __construct($filename) { Twig_Autoloader::register(); $this->fileName = $filename; $this->data = array(); $this->init(); }
function display() { Twig_Autoloader::register(); $loader = new Twig_Loader_Filesystem('/path/to/templates'); $twig = new Twig_Environment($loader, array('cache' => '/path/to/compilation_cache')); echo $view; }
function __construct($data = [], $templateSource = '/templates/') { Twig_Autoloader::register(); $loader = new Twig_Loader_Filesystem(ROOT . $templateSource); $this->twig = new Twig_Environment($loader); $this->data = $data; }
/** * Spawns a new instance of Twig. * * @return object **/ protected function spawn() { // register the Twig autoloader. Twig_Autoloader::register(); // Init the Twig loader. $loader = new Twig_Loader_String(); // check if the cache dir is set. if ($this->compile_dir) { if (is_null($this->debug)) { $this->debug = is_dev_mode(); } $twig = new Twig_Environment($loader, array('autoescape' => FALSE, 'cache' => $this->compile_dir, 'debug' => $this->debug, 'charset' => $this->charset, 'base_template_class' => $this->base_template_class, 'strict_variables' => $this->strict_variables, 'autoescape' => $this->autoescape, 'optimizations' => $this->optimizations)); } else { $twig = new Twig_Environment($loader, array('autoescape' => FALSE)); } // init all functions as Twig functions. foreach ($this->allowed_functions as $function) { $twig->addFunction($function, new Twig_Function_Function($function)); } // setup debugger $twig->addExtension(new Twig_Extension_Debug()); // setup the Lexer $lexer = new Twig_Lexer($twig, $this->delimiters); $twig->setLexer($lexer); // finally, return the object. return $twig; }
function startTwig() { require_once 'Twig/lib/Twig/Autoloader.php'; Twig_Autoloader::register(); $loader = new Twig_Loader_Filesystem('templates/'); return $twig = new Twig_Environment($loader); }
public function __construct() { $this->parseUri(); \Twig_Autoloader::register(); $loader = new \Twig_Loader_Filesystem(__DIR__ . "/Views"); $this->twig = new \Twig_Environment($loader, array('cache' => false, 'debug' => true, 'strict_variables' => true)); }
function __construct() { $this->CI =& get_instance(); $this->CI->config->load('twig'); ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . APPPATH . 'libraries/Twig'); require_once (string) 'Autoloader.php'; log_message('debug', "Twig Autoloader Loaded"); Twig_Autoloader::register(); if ($this->CI->uri->segment(1) == 'setup') { $this->_template_dir = $this->CI->config->item('template_dir') . '/install'; } else { $this->_template_dir = $this->CI->config->item('template_dir') . '/' . get_active_theme(); } $this->_cache_dir = $this->CI->config->item('cache_dir'); $loader = new Twig_Loader_Filesystem($this->_template_dir); $this->_twig = new Twig_Environment($loader, array('cache' => $this->_cache_dir, 'debug' => true)); foreach (get_defined_functions() as $functions) { foreach ($functions as $function) { $this->_twig->addFunction($function, new Twig_Function_Function($function)); } } # untuk decode iframe youtube yang di encode $filter = new Twig_SimpleFilter('raw_youtube', function ($string) { if (strpos($string, '<iframe src="http://www.youtube.com/embed/') !== false) { $string = str_replace('<iframe src="http://www.youtube.com/embed/', '<iframe src="http://www.youtube.com/embed/', $string); $string .= str_replace('></iframe>', '></iframe>', $string); } return $string; }); $this->_twig->addFilter($filter); }
public function __construct() { \Twig_Autoloader::register(); $this->loader = new \Twig_Loader_Filesystem([$this->view_path]); $this->twig = new \Twig_Environment($this->loader, array('debug ' => true, 'cache' => false, 'optimizations' => 1, 'strict_variables' => true)); //$this->twig->addExtension(new TwigExtensionCore()); }
private function set_report_form() { Twig_Autoloader::register(true); $loader = new Twig_Loader_Filesystem('configs/' . $this->config['name'] . '/templates/'); $twig = new Twig_Environment($loader); return $twig->render('report.html', $this->field); }
public function __construct() { if (file_exists(dirname(dirname(__FILE__)) . "/Twig/Autoloader.php")) { require_once dirname(dirname(__FILE__)) . "/Twig/Autoloader.php"; } Twig_Autoloader::register(); }
/** * Constructor. * * @param IOInterface $io * @param TwigFactory $twigFactory * @param string $serverroot * @param string $documentroot * @param int $port * @param string $host */ public function __construct(IOInterface $io, $serverroot, $documentroot, $port, $host) { \Twig_Autoloader::register(); $this->io = $io; $this->port = $port; $this->host = $host; $this->documentroot = $documentroot; $this->buildTwig($serverroot); $this->requestHandler = new RequestHandler(function (Request $request) { $resourcePath = $this->resolvePath($request); if ($this->onBeforeHandleRequestFunction) { try { call_user_func($this->onBeforeHandleRequestFunction, $request, $resourcePath, $this->io); } catch (\Exception $e) { $this->logRequest($request, 500); return $this->getResponseError(500, $e->getMessage()); } } if (false === file_exists($resourcePath)) { $this->logRequest($request, 404); return $this->getResponseError(404, $resourcePath); } $content = file_get_contents($resourcePath); $contentType = $this->getMimeTypeFile($resourcePath); $this->logRequest($request, 200); return $this->getResponseOk($content, $contentType); }); $this->requestHandler->listen($port, $host)->enableHttpFoundationRequest(); }
/** * @fn function init(&$rooter, &$objet) * @brief * @file controller.php * * @param rooter * @param objet * @return */ public function init(&$rooter, &$objet) { include_once dirname(__FILE__) . '/library/redis/Autoloader.php'; Predis\Autoloader::register(); require_once "./" . PATH_LIB . "twig/lib/Twig/Autoloader.php"; Twig_Autoloader::register(); $dont = array("rooter" => 0, "error" => 0); include_once "model.php"; $this->root = $rooter; $this->class['root'] = $rooter; $array = glob("./" . PATH_LIB . "*.php"); foreach ($array as $value) { $temp = str_replace(".php", "", str_replace("./" . PATH_LIB, "", $value)); if (array_key_exists($temp, $dont) === FALSE) { $this->loadLibrary($temp); } } $this->class['redis'] = new Predis\Client("tcp://127.0.0.1:6379"); $this->init_variables(); $this->model = $this->loadModel($this->models, $this->module); foreach ($this->class as $obj) { if (method_exists($obj, "loadLib")) { $obj->loadLib($this->class); } } $this->start($objet); }
/** * Includes the dwooAutoload php * * @param string $twigAutoloaderUri /URI/of/twig/Autoloader.php * @param string $cachePath * @param string $templatesPath */ public function __construct($twigAutoloaderUri, $cachePath = false, $templatesPath = null) { parent::__construct($templatesPath); require_once $twigAutoloaderUri; Twig_Autoloader::register(); $this->cachePath = $cachePath; }
function __construct() { /** * File System and config */ $this->filesystem = new Filesystem(new Adapter($_SERVER['DOCUMENT_ROOT'])); $this->config = $this->getConfig(); /** * YAML Parser/Dumper */ $this->yml = new Parser(); $this->dumper = new Dumper(); /** * Templating Engine */ Twig_Autoloader::register(); $loader = new Twig_Loader_Filesystem($_SERVER['DOCUMENT_ROOT'] . '/app/views'); $this->twig = new Twig_Environment($loader, array('debug' => true)); /** * Router */ $this->router = $this->routes(new Phrouter()); $this->filters($this->router); $this->dispatcher = new Dispatcher($this->router); $this->serveResponse($this->dispatcher); }