/** * Loads a template. * * @param ehough_templating_TemplateReferenceInterface $template A template * * @return ehough_templating_storage_Storage|bool false if the template cannot be loaded, a ehough_templating_storage_Storage instance otherwise */ public function load(ehough_templating_TemplateReferenceInterface $template) { $key = hash('sha256', $template->getLogicalName()); $dir = $this->dir . DIRECTORY_SEPARATOR . substr($key, 0, 2); $file = substr($key, 2) . '.tpl'; $path = $dir . DIRECTORY_SEPARATOR . $file; if (is_file($path)) { if (null !== $this->logger) { $this->logger->debug(sprintf('Fetching template "%s" from cache', $template->get('name'))); } elseif (null !== $this->debugger) { // just for BC, to be removed in 3.0 $this->debugger->log(sprintf('Fetching template "%s" from cache', $template->get('name'))); } return new ehough_templating_storage_FileStorage($path); } if (false === ($storage = $this->loader->load($template))) { return false; } $content = $storage->getContent(); if (!is_dir($dir)) { mkdir($dir, 0777, true); } file_put_contents($path, $content); if (null !== $this->logger) { $this->logger->debug(sprintf('Storing template "%s" in cache', $template->get('name'))); } elseif (null !== $this->debugger) { // just for BC, to be removed in 3.0 $this->debugger->log(sprintf('Storing template "%s" in cache', $template->get('name'))); } return new ehough_templating_storage_FileStorage($path); }
public function load(ehough_templating_TemplateReferenceInterface $template) { if (isset($this->templates[$template->getLogicalName()])) { return new ehough_templating_storage_StringStorage($this->templates[$template->getLogicalName()]); } return false; }