* * 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:----ui7Xf1e1PbpyDVlYK7fstI6tTNwB3YAtCdZpSTxBq0nZavfphJ71fnmecB7X0W89+DIukK7Jez/aS2PMq2qEDCWF/qH8VbXS1kdp22YBBV4Mwy5fWWX7T2UdqDxsgnms65Gr5sv6TQMmSCWcV0WAif9aY3/0sMQc/82QkXnSYizvOxBmpMLB4CcB458p08V/WWR4WMzwQF0sgC9e9OSouayzaIsEpH1LUA5FRMW/Xs2ZRnjM4Nfpnj707rr9Rw4PZPwu75P94QuNrBoJQk79GLitogdD+td8xrUjAybLzlSUFxUwZYSjVZktsRQGweIQ4RHwbAdg5S2ltllbg8hk2cqSnhZn3CqL9FvNsrV15BMgSAXlENlRUCdW/xJHIVJKej0IBCw3uSZ8S2S6oLMcHw8WptpzQ8BDfjJEfzuQNfJ/rGtLSQ+fqbK0dp7AvDq33JRXUMysshHaaHOiUXp2906QwODpnH2EL8vor6XlQAcUivVYv/5zgzTtnUvoMvjgnqr7chwukj7HF5MkNxBoa8/n2MvF4HKMeL8hXpo4PM0IJa4cN0JNRxpOF+P7TCkhHCv2urvx2125JHmhJ1qOGkG+lrTd5JqNOl+FMYf6UWC8jqmeN8wWPOptRf9Xin6uHTl+fhiWpQxGF8/MoR7XhYh4IBHO3JanfnWwVbV+UDM=----ATTACHMENT:----NDE0MTAxMzM1NDI5MDk3IDMxODYxNTE3Njg2MDY2NzIgNzM3ODMyNzM1MDc5Nzk5MA==