2011-01-24 10:27:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-01-24 10:27:07 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2011-01-27 11:22:32 +00:00
|
|
|
namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
|
2011-01-24 10:27:07 +00:00
|
|
|
|
2011-04-05 20:04:00 +01:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator;
|
2016-08-20 22:08:57 +01:00
|
|
|
use Symfony\Component\Filesystem\Filesystem;
|
2011-01-24 10:27:07 +00:00
|
|
|
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Computes the association between template names and their paths on the disk.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
2011-01-24 10:27:07 +00:00
|
|
|
*/
|
|
|
|
class TemplatePathsCacheWarmer extends CacheWarmer
|
|
|
|
{
|
2011-04-14 17:23:13 +01:00
|
|
|
protected $finder;
|
2011-04-05 20:04:00 +01:00
|
|
|
protected $locator;
|
2011-01-24 10:27:07 +00:00
|
|
|
|
2011-04-14 17:23:13 +01:00
|
|
|
public function __construct(TemplateFinderInterface $finder, TemplateLocator $locator)
|
2011-01-24 10:27:07 +00:00
|
|
|
{
|
2011-04-14 17:23:13 +01:00
|
|
|
$this->finder = $finder;
|
2011-04-05 20:04:00 +01:00
|
|
|
$this->locator = $locator;
|
2011-01-24 10:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Warms up the cache.
|
|
|
|
*
|
|
|
|
* @param string $cacheDir The cache directory
|
|
|
|
*/
|
|
|
|
public function warmUp($cacheDir)
|
2011-03-18 10:23:23 +00:00
|
|
|
{
|
2017-02-28 14:23:14 +00:00
|
|
|
$filesystem = new Filesystem();
|
2011-02-24 10:07:22 +00:00
|
|
|
$templates = array();
|
|
|
|
|
2011-04-14 17:23:13 +01:00
|
|
|
foreach ($this->finder->findAllTemplates() as $template) {
|
2017-02-28 14:23:14 +00:00
|
|
|
$templates[$template->getLogicalName()] = rtrim($filesystem->makePathRelative($this->locator->locate($template), $cacheDir), '/');
|
2011-02-24 10:07:22 +00:00
|
|
|
}
|
|
|
|
|
2016-08-20 22:08:57 +01:00
|
|
|
$templates = str_replace("' => '", "' => __DIR__.'/", var_export($templates, true));
|
|
|
|
|
|
|
|
$this->writeCacheFile($cacheDir.'/templates.php', sprintf("<?php return %s;\n", $templates));
|
2011-01-24 10:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether this warmer is optional or not.
|
|
|
|
*
|
2014-11-30 13:33:44 +00:00
|
|
|
* @return bool always true
|
2011-01-24 10:27:07 +00:00
|
|
|
*/
|
|
|
|
public function isOptional()
|
|
|
|
{
|
2011-06-07 10:36:32 +01:00
|
|
|
return true;
|
2011-01-24 10:27:07 +00:00
|
|
|
}
|
|
|
|
}
|