Example #1
0
    /**
     * Loads a template.
     *
     * @param TemplateReferenceInterface $template A template
     *
     * @return Storage|Boolean false if the template cannot be loaded, a Storage instance otherwise
     */
    public function load(TemplateReferenceInterface $template)
    {
        $key = $template->getSignature();
        $dir = $this->dir.DIRECTORY_SEPARATOR.substr($key, 0, 2);
        $file = substr($key, 2).'.tpl';
        $path = $dir.DIRECTORY_SEPARATOR.$file;

        if (file_exists($path)) {
            if (null !== $this->debugger) {
                $this->debugger->log(sprintf('Fetching template "%s" from cache', $template->get('name')));
            }

            return new FileStorage($path);
        }

        if (false === $storage = $this->loader->load($template)) {
            return false;
        }

        $content = $storage->getContent();

        if (!file_exists($dir)) {
            mkdir($dir, 0777, true);
        }

        file_put_contents($path, $content);

        if (null !== $this->debugger) {
            $this->debugger->log(sprintf('Storing template "%s" in cache', $template->get('name')));
        }

        return new FileStorage($path);
    }
 /**
  * Returns a full path for a given file.
  *
  * @param TemplateReferenceInterface $template    The template
  * @param string                     $currentPath Unused
  * @param Boolean                    $first       Unused
  *
  * @return string The full path for the file
  *
  * @throws \InvalidArgumentException When file is not found
  */
 public function locate($template, $currentPath = null, $first = true)
 {
     $key = $template->getSignature();
     if (!isset($this->templates[$key])) {
         return parent::locate($template, $currentPath, $first);
     }
     return $this->templates[$key];
 }
 /**
  * Returns a full path for a given file.
  *
  * @param TemplateReferenceInterface $template    The template
  * @param string                     $currentPath Unused
  * @param Boolean                    $first       Unused
  *
  * @return string The full path for the file
  *
  * @throws \InvalidArgumentException When file is not found
  */
 public function locate($template, $currentPath = null, $first = true)
 {
     $key = $template->getSignature();
     if (!isset($this->templates[$key])) {
         throw new \InvalidArgumentException(sprintf('Unable to find template "%s".', json_encode($template)));
     }
     return $this->templates[$key];
 }
 /**
  * Returns a full path for a given file.
  *
  * @param TemplateReferenceInterface    $template     A template
  * @param string                        $currentPath  Unused
  * @param Boolean                       $first        Unused
  *
  * @return string The full path for the file
  *
  * @throws \InvalidArgumentException When file is not found
  */
 public function locate($template, $currentPath = null, $first = true)
 {
     $key = $template->getSignature();
     if (isset($this->cache[$key])) {
         return $this->cache[$key];
     }
     try {
         return $this->cache[$key] = $this->locator->locate($template->getPath(), $this->path);
     } catch (\InvalidArgumentException $e) {
         throw new \InvalidArgumentException(sprintf('Unable to find template "%s" in "%s".', $template, $this->path), 0, $e);
     }
 }
Example #5
0
 /**
  * Returns a full path for a given file.
  *
  * @param TemplateReferenceInterface    $template     A template
  * @param string                        $currentPath  Unused
  * @param Boolean                       $first        Unused
  *
  * @return string The full path for the file
  *
  * @throws \InvalidArgumentException When the template is not an instance of TemplateReferenceInterface
  * @throws \InvalidArgumentException When the template file can not be found
  */
 public function locate($template, $currentPath = null, $first = true)
 {
     if (!$template instanceof TemplateReferenceInterface) {
         throw new \InvalidArgumentException("The template must be an instance of TemplateReferenceInterface.");
     }
     $key = $template->getSignature();
     if (isset($this->cache[$key])) {
         return $this->cache[$key];
     }
     try {
         return $this->cache[$key] = $this->locator->locate($template->getPath(), $currentPath);
     } catch (\InvalidArgumentException $e) {
         throw new \InvalidArgumentException(sprintf('Unable to find template "%s" in "%s".', $template, $this->path), 0, $e);
     }
 }
Example #6
0
 public function load(TemplateReferenceInterface $template)
 {
     if (isset($this->templates[$template->getSignature()])) {
         return new StringStorage($this->templates[$template->getSignature()]);
     }
     return false;
 }
 /**
  * Returns the template path from the cache
  * 
  * @param TemplateReferenceInterface $template The template
  * 
  * @return string|null The path when it is present in the cache, false otherwise
  */
 protected function getCachedTemplatePath(TemplateReferenceInterface $template)
 {
     $key = $template->getSignature();
     return isset($this->templates[$key]) ? $this->templates[$key] : null;
 }