vendor/symfony/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php
equal
deleted
inserted
replaced
|
1 <?php |
|
2 |
|
3 /* |
|
4 * This file is part of the Symfony package. |
|
5 * |
|
6 * (c) Fabien Potencier <fabien@symfony.com> |
|
7 * |
|
8 * For the full copyright and license information, please view the LICENSE |
|
9 * file that was distributed with this source code. |
|
10 */ |
|
11 |
|
12 namespace Symfony\Bundle\FrameworkBundle\CacheWarmer; |
|
13 |
|
14 use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer; |
|
15 use Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator; |
|
16 |
|
17 /** |
|
18 * Computes the association between template names and their paths on the disk. |
|
19 * |
|
20 * @author Fabien Potencier <fabien@symfony.com> |
|
21 */ |
|
22 class TemplatePathsCacheWarmer extends CacheWarmer |
|
23 { |
|
24 protected $finder; |
|
25 protected $locator; |
|
26 |
|
27 /** |
|
28 * Constructor. |
|
29 * |
|
30 * @param TemplateFinderInterface $finder A template finder |
|
31 * @param TemplateLocator $locator The template locator |
|
32 */ |
|
33 public function __construct(TemplateFinderInterface $finder, TemplateLocator $locator) |
|
34 { |
|
35 $this->finder = $finder; |
|
36 $this->locator = $locator; |
|
37 } |
|
38 |
|
39 /** |
|
40 * Warms up the cache. |
|
41 * |
|
42 * @param string $cacheDir The cache directory |
|
43 */ |
|
44 public function warmUp($cacheDir) |
|
45 { |
|
46 $templates = array(); |
|
47 |
|
48 foreach ($this->finder->findAllTemplates() as $template) { |
|
49 $templates[$template->getLogicalName()] = $this->locator->locate($template); |
|
50 } |
|
51 |
|
52 $this->writeCacheFile($cacheDir.'/templates.php', sprintf('<?php return %s;', var_export($templates, true))); |
|
53 } |
|
54 |
|
55 /** |
|
56 * Checks whether this warmer is optional or not. |
|
57 * |
|
58 * @return Boolean always true |
|
59 */ |
|
60 public function isOptional() |
|
61 { |
|
62 return true; |
|
63 } |
|
64 } |