当前位置: 首页>>代码示例>>PHP>>正文


PHP Twig_Autoloader类代码示例

本文整理汇总了PHP中Twig_Autoloader的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Autoloader类的具体用法?PHP Twig_Autoloader怎么用?PHP Twig_Autoloader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Twig_Autoloader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 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"');
 }
开发者ID:bacbos,项目名称:bacbox,代码行数:25,代码来源:ResponseTwigString.php

示例2: testAutoload

 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');
 }
开发者ID:nmcteam,项目名称:Twig,代码行数:7,代码来源:AutoloaderTest.php

示例3: __construct

 /**
  * 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();
 }
开发者ID:jjk-jacky,项目名称:Spress,代码行数:42,代码来源:HttpServer.php

示例4: __construct

    /**
     * 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;
        }
    }
开发者ID:junichiro,项目名称:zend-view-twig,代码行数:34,代码来源:Twig.php

示例5: __construct

 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);
         }
     }
 }
开发者ID:JermingFan,项目名称:AdminLTE-CI,代码行数:35,代码来源:Twig.php

示例6: __construct

 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());
     }
 }
开发者ID:uwmadisoncals,项目名称:Cluster-Plugins,代码行数:26,代码来源:class-template.php

示例7: template

 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;
 }
开发者ID:arunprasathb,项目名称:KMF-MVC,代码行数:31,代码来源:View.php

示例8: getTemplate

 public function getTemplate($name)
 {
     Twig_Autoloader::register();
     $loader = new Twig_Loader_Filesystem('app/templates');
     $twig = new Twig_Environment($loader, []);
     return $twig->loadTemplate($name);
 }
开发者ID:Roma48,项目名称:AdvancedPhpHomeworkComposer,代码行数:7,代码来源:HomeController.php

示例9: init

 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']));
 }
开发者ID:chernogolov,项目名称:blank,代码行数:7,代码来源:Twig.php

示例10: getEnvironment

 /**
  * 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;
 }
开发者ID:Halfnhav4,项目名称:datawrapper,代码行数:31,代码来源:TwigView.php

示例11: __construct

 public function __construct()
 {
     $this->model = new Model();
     Twig_Autoloader::register();
     $this->loader = new Twig_Loader_Filesystem('../templates/');
     $this->twig = new Twig_Environment($this->loader);
 }
开发者ID:Dawakings,项目名称:hellodawa,代码行数:7,代码来源:Controller.php

示例12: Autoloader

 /**
  * 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();
 }
开发者ID:alejofix,项目名称:Mejoramiento,代码行数:15,代码来源:ManejoErrores.php

示例13: __construct

 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;
 }
开发者ID:microlefes,项目名称:Game,代码行数:26,代码来源:template.inc.php

示例14: view

 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);
 }
开发者ID:frankinedinburgh,项目名称:codeigniter_sandbox,代码行数:25,代码来源:Pages.php

示例15: __construct

 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();
     }
 }
开发者ID:RomanWebDev,项目名称:RFOnlineOpenOffice,代码行数:29,代码来源:Twig.php


注:本文中的Twig_Autoloader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。