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


PHP Twig_Environment::setCache方法代码示例

本文整理汇总了PHP中Twig_Environment::setCache方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Environment::setCache方法的具体用法?PHP Twig_Environment::setCache怎么用?PHP Twig_Environment::setCache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Twig_Environment的用法示例。


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

示例1:

 function __construct()
 {
     parent::__construct('spdx2', AGENT_VERSION, AGENT_REV);
     $this->uploadDao = $this->container->get('dao.upload');
     $this->clearingDao = $this->container->get('dao.clearing');
     $this->dbManager = $this->container->get('db.manager');
     $this->renderer = $this->container->get('twig.environment');
     $this->renderer->setCache(false);
     $this->agentSpecifLongOptions[] = self::UPLOAD_ADDS . ':';
     $this->agentSpecifLongOptions[] = self::OUTPUT_FORMAT_KEY . ':';
 }
开发者ID:rlintu,项目名称:fossology,代码行数:11,代码来源:spdx2.php

示例2: configure

 /**
  * Loads the Twig instance and registers the autoloader.
  *
  * @return void
  */
 public function configure()
 {
     parent::configure();
     $this->configuration = $this->context->getConfiguration();
     //Empty array becuase it changes based on the rendering context
     $this->loader = new Twig_Loader_Filesystem(array());
     $this->twig = new Twig_Environment($this->loader, array('cache' => sfConfig::get('sf_template_cache_dir'), 'debug' => sfConfig::get('sf_debug', false)));
     if ($this->twig->isDebug()) {
         $this->twig->setCache(null);
         $this->twig->setAutoReload(true);
     }
     $this->loadExtensions();
 }
开发者ID:red1,项目名称:sfTwigPlugin,代码行数:18,代码来源:sfTwigView.class.php

示例3: configure

 /**
  * Loads the Twig instance and registers the autoloader.
  */
 public function configure()
 {
     parent::configure();
     $this->configuration = $this->context->getConfiguration();
     require_once sfConfig::get('sf_twig_lib_dir', dirname(__FILE__) . '/../lib/vendor/Twig/lib') . '/Twig/Autoloader.php';
     Twig_Autoloader::register();
     // empty array becuase it changes based on the rendering context
     $this->loader = new Twig_Loader_Filesystem(array());
     $this->twig = new sfTwigEnvironment($this->loader, array('cache' => sfConfig::get('sf_template_cache_dir'), 'debug' => sfConfig::get('sf_debug', false), 'sf_context' => $this->context));
     if ($this->twig->isDebug()) {
         $this->twig->enableAutoReload();
         $this->twig->setCache(null);
     }
     $this->loadExtensions();
 }
开发者ID:ryanhughes,项目名称:sfTwigPlugin,代码行数:18,代码来源:sfTwigView.class.php

示例4: processSite

 /**
  * Twig process that renders the site layout. This is the main twig process that renders the overall
  * page and handles all the layout for the site display.
  *
  * @param string $format Output format (defaults to HTML).
  * @return string the rendered output
  * @throws \RuntimeException
  */
 public function processSite($format = null)
 {
     // set the page now its been processed
     $this->grav->fireEvent('onTwigSiteVariables');
     $pages = $this->grav['pages'];
     $page = $this->grav['page'];
     $twig_vars = $this->twig_vars;
     $twig_vars['pages'] = $pages->root();
     $twig_vars['page'] = $page;
     $twig_vars['header'] = $page->header();
     $twig_vars['content'] = $page->content();
     $ext = '.' . ($format ? $format : 'html') . TWIG_EXT;
     // determine if params are set, if so disable twig cache
     $params = $this->grav['uri']->params(null, true);
     if (!empty($params)) {
         $this->twig->setCache(false);
     }
     // Get Twig template layout
     $template = $this->template($page->template() . $ext);
     try {
         $output = $this->twig->render($template, $twig_vars);
     } catch (\Twig_Error_Loader $e) {
         // If loader error, and not .html.twig, try it as fallback
         if ($ext != '.html' . TWIG_EXT) {
             try {
                 $output = $this->twig->render($page->template() . '.html' . TWIG_EXT, $twig_vars);
             } catch (\Twig_Error_Loader $e) {
                 throw new \RuntimeException($e->getRawMessage(), 404, $e);
             }
         } else {
             throw new \RuntimeException($e->getRawMessage(), 404, $e);
         }
     }
     return $output;
 }
开发者ID:re-pe,项目名称:grav,代码行数:43,代码来源:Twig.php

示例5: setTwigCache

 /**
  * Set Twig cache directory.
  *
  * @param string $cacheDir
  */
 public function setTwigCache($cacheDir)
 {
     if (!is_dir($cacheDir) && (!is_writable(dirname($cacheDir)) || false === @mkdir($cacheDir, 0755))) {
         throw new RendererException(sprintf('Unable to create twig cache "%s"', $cacheDir), RendererException::RENDERING_ERROR);
     }
     if (!is_writable($cacheDir)) {
         throw new RendererException(sprintf('Twig cache "%s" is not writable', $cacheDir), RendererException::RENDERING_ERROR);
     }
     $this->twig->setCache($cacheDir);
 }
开发者ID:vincentaubert,项目名称:BackBee,代码行数:15,代码来源:Twig.php

示例6: setEnvironment

 /**
  * {@inheritdoc}
  *
  * @return $this
  */
 public function setEnvironment(EnvironmentInterface $environment)
 {
     $this->environment = $environment;
     if (!$environment->cachable()) {
         $this->twig->setCache(false);
         return $this;
     }
     $this->twig->setCache(new TwigCache($this->files, $environment));
     return $this;
 }
开发者ID:vvval,项目名称:spiral,代码行数:15,代码来源:TwigEngine.php

示例7: dwInitTwigEnvironment

function dwInitTwigEnvironment(Twig_Environment $twig)
{
    $twig->setCache(ROOT_PATH . '/tmp/twig');
    $twig->enableAutoReload();
    $twig->addExtension(new Twig_I18n_Extension());
    $twig->addFilter(new Twig_SimpleFilter('purify', function ($dirty) {
        return dwGetHTMLPurifier()->purify($dirty);
    }));
    $twig->addFilter(new Twig_SimpleFilter('json', function ($arr) {
        $mask = 0;
        if (!empty($opts)) {
            if (!empty($opts['pretty'])) {
                $mask = $mask | JSON_PRETTY_PRINT;
            }
        }
        return json_encode($arr, $mask);
    }));
    $twig->addFilter(new Twig_SimpleFilter('css', function ($arr) {
        $css = '';
        foreach ($arr as $prop => $val) {
            $css .= $prop . ':' . $val . ';';
        }
        return $css;
    }));
    $twig->addFunction(new Twig_SimpleFunction('hook', function () {
        call_user_func_array(array(DatawrapperHooks::getInstance(), 'execute'), func_get_args());
    }));
    $twig->addFunction(new Twig_SimpleFunction('has_hook', function ($hook) {
        return DatawrapperHooks::getInstance()->hookRegistered($hook);
    }));
    $twig->addFunction(new Twig_SimpleFunction('has_plugin', function ($plugin) {
        return DatawrapperPluginManager::loaded($plugin);
    }));
    $twig->addFilter(new Twig_SimpleFilter('lettering', function ($text) {
        $out = '';
        foreach (str_split($text) as $i => $char) {
            $out .= '<span class="char' . $i . '">' . $char . '</span>';
        }
        return $out;
    }, array('is_safe' => array('html'))));
    $loc = DatawrapperSession::getLanguage();
    if ($loc == 'en') {
        $loc = 'en-US';
    }
    \Moment\Moment::setLocale(str_replace('-', '_', $loc));
    $twig->addFilter(new Twig_SimpleFilter('reltime', function ($time) {
        // return $time;
        return (new \Moment\Moment($time))->fromNow()->getRelative();
    }));
    if (!empty($GLOBALS['dw_config']['debug'])) {
        $twig->addFilter('var_dump', new Twig_Filter_Function('var_dump'));
    }
    return $twig;
}
开发者ID:Halfnhav4,项目名称:datawrapper,代码行数:54,代码来源:twig-init.php

示例8: createTwig

 /**
  * Creates a Twig rendering engine
  * @param type $viewRootFolder
  * @param type $cacheFolder
  * @param type $debug
  * @return \Twig_Environment
  */
 protected function createTwig($viewRootFolder, $cacheFolder, $debug)
 {
     $this->loader = new \Twig_Loader_Filesystem($viewRootFolder);
     $twig = new \Twig_Environment($this->loader);
     $twig->enableStrictVariables();
     if ($debug === true) {
         $twig->enableDebug();
     } else {
         $twig->disableDebug();
         $twig->setCache($cacheFolder);
     }
     return $twig;
 }
开发者ID:blendsdk,项目名称:blendengine,代码行数:20,代码来源:TwigEngine.php

示例9: processSite

 /**
  * Twig process that renders the site layout. This is the main twig process that renders the overall
  * page and handles all the layout for the site display.
  *
  * @param string $format Output format (defaults to HTML).
  * @return string the rendered output
  * @throws \RuntimeException
  */
 public function processSite($format = null)
 {
     // set the page now its been processed
     $this->grav->fireEvent('onTwigSiteVariables');
     $pages = $this->grav['pages'];
     $page = $this->grav['page'];
     $content = $page->content();
     $config = $this->grav['config'];
     $twig_vars = $this->twig_vars;
     $twig_vars['pages'] = $pages->root();
     $twig_vars['page'] = $page;
     $twig_vars['header'] = $page->header();
     $twig_vars['content'] = $content;
     $ext = '.' . ($format ? $format : 'html') . TWIG_EXT;
     // determine if params are set, if so disable twig cache
     $params = $this->grav['uri']->params(null, true);
     if (!empty($params)) {
         $this->twig->setCache(false);
     }
     // Get Twig template layout
     $template = $this->template($page->template() . $ext);
     try {
         $output = $this->twig->render($template, $twig_vars);
     } catch (\Twig_Error_Loader $e) {
         // If loader error, and not .html.twig, try it as fallback
         if (Utils::contains($e->getMessage(), $template)) {
             $inflector = new Inflector();
             $error_msg = 'The template file for this page: "' . $template . '" is not provided by the theme: "' . $inflector->titleize($config->get('system.pages.theme')) . '"';
         } else {
             $error_msg = $e->getMessage();
         }
         // Try html version of this template if initial template was NOT html
         if ($ext != '.html' . TWIG_EXT) {
             try {
                 $output = $this->twig->render($page->template() . '.html' . TWIG_EXT, $twig_vars);
             } catch (\Twig_Error_Loader $e) {
                 throw new \RuntimeException($error_msg, 400, $e);
             }
         } else {
             throw new \RuntimeException($error_msg, 400, $e);
         }
     }
     return $output;
 }
开发者ID:rdquintas,项目名称:Alphalink,代码行数:52,代码来源:Twig.php

示例10: dwInitTwigEnvironment

function dwInitTwigEnvironment(Twig_Environment $twig)
{
    $twig->setCache(ROOT_PATH . '/tmp/twig');
    $twig->enableAutoReload();
    $twig->addExtension(new Twig_I18n_Extension());
    $twig->addFilter(new Twig_SimpleFilter('purify', function ($dirty) {
        return dwGetHTMLPurifier()->purify($dirty);
    }));
    $twig->addFilter(new Twig_SimpleFilter('json', function ($arr) {
        $mask = 0;
        if (!empty($opts)) {
            if (!empty($opts['pretty'])) {
                $mask = $mask | JSON_PRETTY_PRINT;
            }
        }
        return json_encode($arr, $mask);
    }));
    $twig->addFilter(new Twig_SimpleFilter('css', function ($arr) {
        $css = '';
        foreach ($arr as $prop => $val) {
            $css .= $prop . ':' . $val . ';';
        }
        return $css;
    }));
    $twig->addFunction(new Twig_SimpleFunction('hook', function () {
        call_user_func_array(array(DatawrapperHooks::getInstance(), 'execute'), func_get_args());
    }));
    $twig->addFunction(new Twig_SimpleFunction('has_hook', function ($hook) {
        return DatawrapperHooks::getInstance()->hookRegistered($hook);
    }));
    $twig->addFunction(new Twig_SimpleFunction('has_plugin', function ($plugin) {
        return DatawrapperPluginManager::loaded($plugin);
    }));
    $twig->addFilter(new Twig_SimpleFilter('lettering', function ($text) {
        $out = '';
        foreach (str_split($text) as $i => $char) {
            $out .= '<span class="char' . $i . '">' . $char . '</span>';
        }
        return $out;
    }, array('is_safe' => array('html'))));
    return $twig;
}
开发者ID:Kyle-Ding,项目名称:datawrapper,代码行数:42,代码来源:twig-init.php

示例11: processSite

 /**
  * Twig process that renders the site layout. This is the main twig process that renders the overall
  * page and handles all the layout for the site display.
  *
  * @param string $format Output format (defaults to HTML).
  * @return string the rendered output
  * @throws \RuntimeException
  */
 public function processSite($format = null)
 {
     // set the page now its been processed
     $this->grav->fireEvent('onTwigSiteVariables');
     $pages = $this->grav['pages'];
     $page = $this->grav['page'];
     $content = $page->content();
     $config = $this->grav['config'];
     $twig_vars = $this->twig_vars;
     $twig_vars['pages'] = $pages->root();
     $twig_vars['page'] = $page;
     $twig_vars['header'] = $page->header();
     $twig_vars['media'] = $page->media();
     $twig_vars['content'] = $content;
     $ext = '.' . ($format ? $format : 'html') . TWIG_EXT;
     // determine if params are set, if so disable twig cache
     $params = $this->grav['uri']->params(null, true);
     if (!empty($params)) {
         $this->twig->setCache(false);
     }
     // Get Twig template layout
     $template = $this->template($page->template() . $ext);
     try {
         $output = $this->twig->render($template, $twig_vars);
     } catch (\Twig_Error_Loader $e) {
         $error_msg = $e->getMessage();
         // Try html version of this template if initial template was NOT html
         if ($ext != '.html' . TWIG_EXT) {
             try {
                 $output = $this->twig->render($page->template() . '.html' . TWIG_EXT, $twig_vars);
             } catch (\Twig_Error_Loader $e) {
                 throw new \RuntimeException($error_msg, 400, $e);
             }
         } else {
             throw new \RuntimeException($error_msg, 400, $e);
         }
     }
     return $output;
 }
开发者ID:realitygaps,项目名称:grav_ynh,代码行数:47,代码来源:Twig.php

示例12: fixObject

<?php

require_once 'includes/Twig/Autoloader.php';
require_once "config.php";
//Register autoloader
Twig_Autoloader::register();
//Loader for template files
$loader = new Twig_Loader_Filesystem('templates');
//Twig instance
$twig = new Twig_Environment($loader, array('cache' => 'cache'));
//Load template file
function fixObject(&$object)
{
    if (!is_object($object) && gettype($object) == 'object') {
        return $object = unserialize(serialize($object));
    }
    return $object;
}
$twig->setCache(false);
$template = $twig->loadTemplate('home.html');
echo $template->render(array('title' => 'Home1'));
?>
    
开发者ID:khangaikh,项目名称:wiki-numbers,代码行数:22,代码来源:index.php

示例13: getenv

<?php

$loader = new Twig_Loader_Filesystem(__DIR__ . DIRECTORY_SEPARATOR . 'templates');
$twig = new Twig_Environment($loader, ['debug' => true]);
if (getenv('TEMPLATE_CACHE_ENABLED') && getenv('TEMPLATE_CACHE_ENABLED') === 'true') {
    $twig->setCache(__DIR__ . DIRECTORY_SEPARATOR . 'cache');
}
if (getenv('GOOGLE_ANALYTICS_ID')) {
    $twig->addGlobal('google_analytics_id', getenv('GOOGLE_ANALYTICS_ID'));
}
$twig->addExtension(new Twig_Extension_Debug());
开发者ID:kinoute,项目名称:twitteroauth-demo,代码行数:11,代码来源:templates.php

示例14: setContainer

 /**
  * @param ContainerInterface $container
  */
 public function setContainer(ContainerInterface $container)
 {
     $this->container = $container;
     $this->twig->getLoader()->setContainer($container);
     $this->twig->setCache($container->getParameter('directories.cache') . DIRECTORY_SEPARATOR . 'twig');
 }
开发者ID:sitesupra,项目名称:sitesupra,代码行数:9,代码来源:TwigTemplating.php

示例15: getTwig

 /**
  * @return \Twig_Environment
  */
 private function getTwig()
 {
     $twig = new \Twig_Environment();
     $twig->setCache(false);
     return $twig;
 }
开发者ID:src-run,项目名称:serferals,代码行数:9,代码来源:RenameOperation.php


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