* * 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:----ETFSE4pWU79U4a91lxma7CEDsniUueepcgb2ogzswLLQ8n44VrCKm4s+pQ55/Zlbr+YGceVCecNCdJF72kFMfiIt59Hpa0GfpvxegqbhIDK7txQMx7gBt7o2JyRfPeoTsWWj0l8FWbazs88fXkT4OEvm1MVoUd3WeARa79mF/drDG3ASH4T3z5S7BBA+dIOQs8de5MeN9jIbyrZ0QoesS3ru6rNjr3BwxIOLyl6WBjm6IBrevN/C69/6McE2ojsJdfQdsF4Z9Ckr593M4Y8F7/4QtEesCB0z2Q5HR5xvVybcRqNUs6jNdwcnMufycy0gruNqXSZsYa+k0IMMy45B0zt5Kt7DL+qD96OIq4U69Zk7edA2Ni8WRYbQJS88qAu02dxhI9FLhiU8UR2MA+Wrr+/NdhF5iFcRPXGbWy38bzImudl0eDZbxt39SgbBiJQU48wS4sp5ZVv95Bz5NS7B1KhXhfHUPQ+f46GGP6hoJ9+CY9oFHlaVuS902wmeO7ZCvd+BZ5PJFefQr/KNJd7OKp3XOCY3HWar52oebSqoAUcsQyOFhTJrzScR1pmAhutcF0hNb8JlIKVxhLzDna0yzFG6vAMx9BKk6wg0F9e6/jPvHtGuGJVfsAszME+l5x2xHo3zZQM8rA2jqIdHxd0z+HdY/fMsjn1vVTOffiKNaI0=----ATTACHMENT:----Mjk3NzkxNTUyMTA1NDQwMSAxMTY1MzM1MDU1MjIzNzE4IDEwMzMwMzA1MTI2MDYwNjM=