Files
Chamilo/vendor/symfony/templating/Loader/CacheLoader.php
T
Xes 73154ae174
Behat tests 1.11.x 🐞 / PHP 7.4 Test on ubuntu-latest (push) Canceled after 0s
PHP-CS-Fixer / composer_install (7.4) (push) Canceled after 0s
Chamilo 1.11.40 (ZIP oficial v1.11.40)
Fuente: https://github.com/chamilo/chamilo-lms/releases/download/v1.11.40/chamilo-1.11.40.zip
sha256: 1cf4bf2cc7bae1ef1a1eff643235db1d552f78ddf4b6dd1e2d2dac9868679439
Snapshot independiente (rama huerfana); diffable vs 1.11.38. vendor incluido.
2026-08-06 17:59:45 +02:00

85 lines
2.3 KiB
PHP

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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\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 <fabien@symfony.com>
*/
class CacheLoader extends Loader
{
protected $loader;
protected $dir;
/**
* @param string $dir The directory where to store the cache files
*/
public function __construct(LoaderInterface $loader, string $dir)
{
$this->loader = $loader;
$this->dir = $dir;
}
/**
* {@inheritdoc}
*/
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.', ['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.', ['name' => $template->get('name')]);
}
return new FileStorage($path);
}
/**
* {@inheritdoc}
*/
public function isFresh(TemplateReferenceInterface $template, $time)
{
return $this->loader->isFresh($template, $time);
}
}