|
@@ -14,8 +14,6 @@ namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
|
|
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer;
|
|
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer;
|
|
use Symfony\Component\HttpKernel\KernelInterface;
|
|
use Symfony\Component\HttpKernel\KernelInterface;
|
|
use Symfony\Component\Finder\Finder;
|
|
use Symfony\Component\Finder\Finder;
|
|
-use Symfony\Component\Config\FileLocatorInterface;
|
|
|
|
-use Symfony\Bundle\FrameworkBundle\Templating\Template;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser;
|
|
use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -25,7 +23,8 @@ use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser;
|
|
*/
|
|
*/
|
|
class TemplatePathsCacheWarmer extends CacheWarmer
|
|
class TemplatePathsCacheWarmer extends CacheWarmer
|
|
{
|
|
{
|
|
- protected $locator;
|
|
|
|
|
|
+ const TEMPLATES_PATH_IN_BUNDLE = '/Resources/views';
|
|
|
|
+
|
|
protected $kernel;
|
|
protected $kernel;
|
|
protected $rootDir;
|
|
protected $rootDir;
|
|
protected $parser;
|
|
protected $parser;
|
|
@@ -34,14 +33,12 @@ class TemplatePathsCacheWarmer extends CacheWarmer
|
|
* Constructor.
|
|
* Constructor.
|
|
*
|
|
*
|
|
* @param KernelInterface $kernel A KernelInterface instance
|
|
* @param KernelInterface $kernel A KernelInterface instance
|
|
- * @param FileLocatorInterface $locator A FileLocatorInterface instance
|
|
|
|
* @param TemplateNameParser $parser A TemplateNameParser instance
|
|
* @param TemplateNameParser $parser A TemplateNameParser instance
|
|
* @param string $rootDir The directory where global templates can be stored
|
|
* @param string $rootDir The directory where global templates can be stored
|
|
*/
|
|
*/
|
|
- public function __construct(KernelInterface $kernel, FileLocatorInterface $locator, TemplateNameParser $parser, $rootDir)
|
|
|
|
|
|
+ public function __construct(KernelInterface $kernel, TemplateNameParser $parser, $rootDir)
|
|
{
|
|
{
|
|
$this->kernel = $kernel;
|
|
$this->kernel = $kernel;
|
|
- $this->locator = $locator;
|
|
|
|
$this->parser = $parser;
|
|
$this->parser = $parser;
|
|
$this->rootDir = $rootDir;
|
|
$this->rootDir = $rootDir;
|
|
}
|
|
}
|
|
@@ -52,8 +49,14 @@ class TemplatePathsCacheWarmer extends CacheWarmer
|
|
* @param string $cacheDir The cache directory
|
|
* @param string $cacheDir The cache directory
|
|
*/
|
|
*/
|
|
public function warmUp($cacheDir)
|
|
public function warmUp($cacheDir)
|
|
- {
|
|
|
|
- $templates = $this->computeTemplatePaths();
|
|
|
|
|
|
+ {
|
|
|
|
+ $templates = array();
|
|
|
|
+
|
|
|
|
+ foreach ($this->kernel->getBundles() as $name => $bundle) {
|
|
|
|
+ $templates += $this->findTemplatesIn($bundle->getPath().self::TEMPLATES_PATH_IN_BUNDLE, $name);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $templates += $this->findTemplatesIn($this->rootDir);
|
|
|
|
|
|
$this->writeCacheFile($cacheDir.'/templates.php', sprintf('<?php return %s;', var_export($templates, true)));
|
|
$this->writeCacheFile($cacheDir.'/templates.php', sprintf('<?php return %s;', var_export($templates, true)));
|
|
}
|
|
}
|
|
@@ -68,35 +71,31 @@ class TemplatePathsCacheWarmer extends CacheWarmer
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- protected function computeTemplatePaths()
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Find templates in the given directory
|
|
|
|
+ *
|
|
|
|
+ * @param string $dir The folder where to look for templates
|
|
|
|
+ * @param string $bundle The name of the bundle (null when out of a bundle)
|
|
|
|
+ *
|
|
|
|
+ * @return array An array of template paths
|
|
|
|
+ */
|
|
|
|
+ protected function findTemplatesIn($dir, $bundle = null)
|
|
{
|
|
{
|
|
- $prefix = '/Resources/views';
|
|
|
|
$templates = array();
|
|
$templates = array();
|
|
- foreach ($this->kernel->getBundles() as $name => $bundle) {
|
|
|
|
- if (!is_dir($dir = $bundle->getPath().$prefix)) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
+ if (is_dir($dir)) {
|
|
$finder = new Finder();
|
|
$finder = new Finder();
|
|
foreach ($finder->files()->followLinks()->in($dir) as $file) {
|
|
foreach ($finder->files()->followLinks()->in($dir) as $file) {
|
|
$template = $this->parser->parseFromFilename($file->getRelativePathname());
|
|
$template = $this->parser->parseFromFilename($file->getRelativePathname());
|
|
if (false !== $template) {
|
|
if (false !== $template) {
|
|
- $template->set('bundle', $name);
|
|
|
|
- $templates[$template->getSignature()] = $this->locator->locate($template->getPath(), $this->rootDir);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (is_dir($this->rootDir)) {
|
|
|
|
- $finder = new Finder();
|
|
|
|
- foreach ($finder->files()->followLinks()->in($this->rootDir) as $file) {
|
|
|
|
- $template = $this->parser->parseFromFilename($file->getRelativePathname());
|
|
|
|
- if (false !== $template) {
|
|
|
|
|
|
+ if (null !== $bundle) {
|
|
|
|
+ $template->set('bundle', $bundle);
|
|
|
|
+ }
|
|
$templates[$template->getSignature()] = $file->getRealPath();
|
|
$templates[$template->getSignature()] = $file->getRealPath();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- return $templates;
|
|
|
|
|
|
+ return $templates;
|
|
}
|
|
}
|
|
}
|
|
}
|