Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * 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;
 }