vendor/symfony/framework-bundle/CacheWarmer/TemplatePathsCacheWarmer.php line 14

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
  11. @trigger_error('The '.TemplatePathsCacheWarmer::class.' class is deprecated since version 4.3 and will be removed in 5.0; use Twig instead.', \E_USER_DEPRECATED);
  12. use Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator;
  13. use Symfony\Component\Filesystem\Filesystem;
  14. use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer;
  15. /**
  16.  * Computes the association between template names and their paths on the disk.
  17.  *
  18.  * @author Fabien Potencier <fabien@symfony.com>
  19.  *
  20.  * @deprecated since version 4.3, to be removed in 5.0; use Twig instead.
  21.  */
  22. class TemplatePathsCacheWarmer extends CacheWarmer
  23. {
  24.     protected $finder;
  25.     protected $locator;
  26.     public function __construct(TemplateFinderInterface $finderTemplateLocator $locator)
  27.     {
  28.         $this->finder $finder;
  29.         $this->locator $locator;
  30.     }
  31.     /**
  32.      * Warms up the cache.
  33.      *
  34.      * @param string $cacheDir The cache directory
  35.      */
  36.     public function warmUp($cacheDir)
  37.     {
  38.         $filesystem = new Filesystem();
  39.         $templates = [];
  40.         foreach ($this->finder->findAllTemplates() as $template) {
  41.             $templates[$template->getLogicalName()] = rtrim($filesystem->makePathRelative($this->locator->locate($template), $cacheDir), '/');
  42.         }
  43.         $templates str_replace("' => '""' => __DIR__.'/"var_export($templatestrue));
  44.         $this->writeCacheFile($cacheDir.'/templates.php'sprintf("<?php return %s;\n"$templates));
  45.     }
  46.     /**
  47.      * Checks whether this warmer is optional or not.
  48.      *
  49.      * @return bool always true
  50.      */
  51.     public function isOptional()
  52.     {
  53.         return true;
  54.     }
  55. }