本文整理汇总了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 . ':';
}
示例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();
}
示例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();
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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'));
?>
示例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());
示例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');
}
示例15: getTwig
/**
* @return \Twig_Environment
*/
private function getTwig()
{
$twig = new \Twig_Environment();
$twig->setCache(false);
return $twig;
}