本文整理汇总了PHP中SSViewer::setPartialCacheStore方法的典型用法代码示例。如果您正苦于以下问题:PHP SSViewer::setPartialCacheStore方法的具体用法?PHP SSViewer::setPartialCacheStore怎么用?PHP SSViewer::setPartialCacheStore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SSViewer
的用法示例。
在下文中一共展示了SSViewer::setPartialCacheStore方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* The process() method handles the "meat" of the template processing.
* It takes care of caching the output (via {@link SS_Cache}),
* as well as replacing the special "$Content" and "$Layout"
* placeholders with their respective subtemplates.
* The method injects extra HTML in the header via {@link Requirements::includeInHTML()}.
*
* Note: You can call this method indirectly by {@link ViewableData->renderWith()}.
*
* @param ViewableData $item
* @param SS_Cache $cache Optional cache backend
* @return String Parsed template output.
*/
public function process($item, $arguments = null)
{
SSViewer::$topLevel[] = $item;
if ($arguments && $arguments instanceof Zend_Cache_Core) {
Deprecation::notice('3.0', 'Use setPartialCacheStore to override the partial cache storage backend, ' . 'the second argument to process is now an array of variables.');
$this->setPartialCacheStore($arguments);
$arguments = null;
}
if (isset($this->chosenTemplates['main'])) {
$template = $this->chosenTemplates['main'];
} else {
$keys = array_keys($this->chosenTemplates);
$key = reset($keys);
$template = $this->chosenTemplates[$key];
}
$cacheFile = TEMP_FOLDER . "/.cache" . str_replace(array('\\', '/', ':'), '.', Director::makeRelative(realpath($template)));
$lastEdited = filemtime($template);
if (!file_exists($cacheFile) || filemtime($cacheFile) < $lastEdited || isset($_GET['flush'])) {
$content = file_get_contents($template);
$content = SSViewer::parseTemplateContent($content, $template);
$fh = fopen($cacheFile, 'w');
fwrite($fh, $content);
fclose($fh);
}
$underlay = array('I18NNamespace' => basename($template));
// Makes the rendered sub-templates available on the parent item,
// through $Content and $Layout placeholders.
foreach (array('Content', 'Layout') as $subtemplate) {
if (isset($this->chosenTemplates[$subtemplate])) {
$subtemplateViewer = new SSViewer($this->chosenTemplates[$subtemplate]);
$subtemplateViewer->setPartialCacheStore($this->getPartialCacheStore());
$underlay[$subtemplate] = $subtemplateViewer->process($item, $arguments);
}
}
$val = $this->includeGeneratedTemplate($cacheFile, $item, $arguments, $underlay);
$output = Requirements::includeInHTML($template, $val);
array_pop(SSViewer::$topLevel);
// If we have our crazy base tag, then fix # links referencing the current page.
if ($this->rewriteHashlinks && self::$options['rewriteHashlinks']) {
if (strpos($output, '<base') !== false) {
if (SSViewer::$options['rewriteHashlinks'] === 'php') {
$thisURLRelativeToBase = "<?php echo strip_tags(\$_SERVER['REQUEST_URI']); ?>";
} else {
$thisURLRelativeToBase = strip_tags($_SERVER['REQUEST_URI']);
}
$output = preg_replace('/(<a[^>]+href *= *)"#/i', '\\1"' . $thisURLRelativeToBase . '#', $output);
}
}
return $output;
}
示例2: process
/**
* The process() method handles the "meat" of the template processing.
*
* It takes care of caching the output (via {@link SS_Cache}), as well as
* replacing the special "$Content" and "$Layout" placeholders with their
* respective subtemplates.
*
* The method injects extra HTML in the header via {@link Requirements::includeInHTML()}.
*
* Note: You can call this method indirectly by {@link ViewableData->renderWith()}.
*
* @param ViewableData $item
* @param array|null $arguments - arguments to an included template
* @param Object $inheritedScope - the current scope of a parent template including a sub-template
*
* @return HTMLText Parsed template output.
*/
public function process($item, $arguments = null, $inheritedScope = null)
{
SSViewer::$topLevel[] = $item;
if (isset($this->chosenTemplates['main'])) {
$template = $this->chosenTemplates['main'];
} else {
$keys = array_keys($this->chosenTemplates);
$key = reset($keys);
$template = $this->chosenTemplates[$key];
}
$cacheFile = TEMP_FOLDER . "/.cache" . str_replace(array('\\', '/', ':'), '.', Director::makeRelative(realpath($template)));
$lastEdited = filemtime($template);
if (!file_exists($cacheFile) || filemtime($cacheFile) < $lastEdited) {
$content = file_get_contents($template);
$content = $this->parseTemplateContent($content, $template);
$fh = fopen($cacheFile, 'w');
fwrite($fh, $content);
fclose($fh);
}
$underlay = array('I18NNamespace' => basename($template));
// Makes the rendered sub-templates available on the parent item,
// through $Content and $Layout placeholders.
foreach (array('Content', 'Layout') as $subtemplate) {
if (isset($this->chosenTemplates[$subtemplate])) {
$subtemplateViewer = new SSViewer($this->chosenTemplates[$subtemplate], $this->parser);
$subtemplateViewer->includeRequirements(false);
$subtemplateViewer->setPartialCacheStore($this->getPartialCacheStore());
$underlay[$subtemplate] = $subtemplateViewer->process($item, $arguments);
}
}
$output = $this->includeGeneratedTemplate($cacheFile, $item, $arguments, $underlay, $inheritedScope);
if ($this->includeRequirements) {
$output = Requirements::includeInHTML($template, $output);
}
array_pop(SSViewer::$topLevel);
// If we have our crazy base tag, then fix # links referencing the current page.
$rewrite = Config::inst()->get('SSViewer', 'rewrite_hash_links');
if ($this->rewriteHashlinks && $rewrite) {
if (strpos($output, '<base') !== false) {
if ($rewrite === 'php') {
$thisURLRelativeToBase = "<?php echo Convert::raw2att(preg_replace(\"/^(\\\\/)+/\", \"/\", \$_SERVER['REQUEST_URI'])); ?>";
} else {
$thisURLRelativeToBase = Convert::raw2att(preg_replace("/^(\\/)+/", "/", $_SERVER['REQUEST_URI']));
}
$output = preg_replace('/(<a[^>]+href *= *)"#/i', '\\1"' . $thisURLRelativeToBase . '#', $output);
}
}
return DBField::create_field('HTMLText', $output, null, array('shortcodes' => false));
}