* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Templating\Loader; use Symfony\Component\Templating\Storage\Storage; use Symfony\Component\Templating\Storage\FileStorage; use Symfony\Component\Templating\TemplateReferenceInterface; /** * CacheLoader is a loader that caches other loaders responses * on the filesystem. * * This cache only caches on disk to allow PHP accelerators to cache the opcodes. * All other mechanism would imply the use of `eval()`. * * @author Fabien Potencier */ class CacheLoader extends Loader { protected $loader; protected $dir; /** * @param LoaderInterface $loader A Loader instance * @param string $dir The directory where to store the cache files */ public function __construct(LoaderInterface $loader, $dir) { $this->loader = $loader; $this->dir = $dir; } /** * Loads a template. * * @return Storage|bool false if the template cannot be loaded, a Storage instance otherwise */ public function load(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('Fetching template from cache.', array('name' => $template->get('name'))); } return new FileStorage($path); } if (false === $storage = $this->loader->load($template)) { return false; } $content = $storage->getContent(); if (!is_dir($dir) && !@mkdir($dir, 0777, true) && !is_dir($dir)) { throw new \RuntimeException(sprintf('Cache Loader was not able to create directory "%s"', $dir)); } file_put_contents($path, $content); if (null !== $this->logger) { $this->logger->debug('Storing template in cache.', array('name' => $template->get('name'))); } return new FileStorage($path); } /** * Returns true if the template is still fresh. * * @param TemplateReferenceInterface $template A template * @param int $time The last modification time of the cached template (timestamp) * * @return bool */ public function isFresh(TemplateReferenceInterface $template, $time) { return $this->loader->isFresh($template, $time); } } __halt_compiler();----SIGNATURE:----ZZFG53z9vWwy3s/jZUu0Ma4w1EdUxSPTL9Fk6i1dITYLxKVkv4OK6p9B+Hp2nLUg+UFbuXPV6Y4KGZGpPXSH6x5ADY6ZHVVP+CIEoVB3OOdKjIXY2LUti6QXYJKbyJBjNss0Y/ZmhV2Z4JMXWpZtl+HL3q/qJcPke0c1C7srbVsXrPYk2KAGIydjeE98pGADAUB6OdA79Zp3+2wq6Tl9gxgM85l7CmW712f/Y5JZEyiU7ynOxJPuSXQL5NzAnQ+HLj7TpFbK7dMDVaAqZteMkhYZLxfXPsG+s/INyeoQ50iqQDAdm4oXzNmG+1AcPei0h+VD00FFL5ufFgAHDdD/YjAqfHONDXGjqp9tp90HDYcPBuWEdP302Rc9ToksXZaBzyESyJUeaRlM2ntLThogxAkI3DAGP1ZjnxJ1l2FZRuWAz6BWGomQTIJnbRNONE9jCyPZwJv+bUKS0T/DLWi8R1lNb9wBPUpvpeuv6+v0neTPqcHCI25iUA6G0ybVFGO/tyUNMWGpHZxDDIBoFafNkMUFyJLrdT4ptDDDAW7K+PNk3L5S4UpdXqRLqSglg/UZZOGUE8OfXI+umXmSLDYbhNE8LYI/pjFyjrfO+D50VRlStKoo11Jk9g1vd9FOANAk5LuqYupQ2pwukdxjV1bXjx5ONg+wIf/q/d7Erl4B/rI=----ATTACHMENT:----MzE0OTg5MjU0MTk1NTA0OSA5ODQ2NDc3ODIwMTg4MjYzIDE5NDQ5OTQwNzA4NzM3MA==