本文整理匯總了PHP中Symfony\Component\Templating\TemplateReferenceInterface::all方法的典型用法代碼示例。如果您正苦於以下問題:PHP TemplateReferenceInterface::all方法的具體用法?PHP TemplateReferenceInterface::all怎麽用?PHP TemplateReferenceInterface::all使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Templating\TemplateReferenceInterface
的用法示例。
在下文中一共展示了TemplateReferenceInterface::all方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: load
/**
* Loads a template.
*
* @param TemplateReferenceInterface $template A template
*
* @return Storage|Boolean false if the template cannot be loaded, a Storage instance otherwise
*
* @api
*/
public function load(TemplateReferenceInterface $template)
{
$file = $template->get('name');
if (self::isAbsolutePath($file) && file_exists($file)) {
return new FileStorage($file);
}
$replacements = array();
foreach ($template->all() as $key => $value) {
$replacements['%' . $key . '%'] = $value;
}
$logs = array();
foreach ($this->templatePathPatterns as $templatePathPattern) {
if (is_file($file = strtr($templatePathPattern, $replacements)) && is_readable($file)) {
if (null !== $this->debugger) {
$this->debugger->log(sprintf('Loaded template file "%s"', $file));
}
return new FileStorage($file);
}
if (null !== $this->debugger) {
$logs[] = sprintf('Failed loading template file "%s"', $file);
}
}
if (null !== $this->debugger) {
foreach ($logs as $log) {
$this->debugger->log($log);
}
}
return false;
}
示例2: load
/**
* Loads a template.
*
* @param TemplateReferenceInterface $template A template
*
* @return Storage|bool false if the template cannot be loaded, a Storage instance otherwise
*/
public function load(TemplateReferenceInterface $template)
{
$file = $template->get('name');
if (self::isAbsolutePath($file) && is_file($file)) {
return new FileStorage($file);
}
$replacements = array();
foreach ($template->all() as $key => $value) {
$replacements['%' . $key . '%'] = $value;
}
$fileFailures = array();
foreach ($this->templatePathPatterns as $templatePathPattern) {
if (is_file($file = strtr($templatePathPattern, $replacements)) && is_readable($file)) {
if (null !== $this->logger) {
$this->logger->debug('Loaded template file.', array('file' => $file));
}
return new FileStorage($file);
}
if (null !== $this->logger) {
$fileFailures[] = $file;
}
}
// only log failures if no template could be loaded at all
foreach ($fileFailures as $file) {
if (null !== $this->logger) {
$this->logger->debug('Failed loading template file.', array('file' => $file));
}
}
return false;
}