src/WellCommerce/Bundle/AppBundle/CacheWarmer/TemplatePathsCacheWarmer.php line 31

Open in your IDE?
  1. <?php
  2. declare(strict_types=0);
  3. /*
  4.  * WellCommerce Foundation
  5.  *
  6.  * This file is part of the WellCommerce package.
  7.  *
  8.  * (c) Adam Piotrowski <adam@wellcommerce.org>, Adrian Potepa <adrian@wellcommerce.org>
  9.  *
  10.  * For the full copyright and license information,
  11.  * please view the LICENSE file that was distributed with this source code.
  12.  */
  13. namespace WellCommerce\Bundle\AppBundle\CacheWarmer;
  14. use Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplatePathsCacheWarmer as BaseTemplatePathsCacheWarmer;
  15. use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
  16. use Symfony\Component\Config\FileLocatorInterface;
  17. /**
  18.  * Class TemplatePathsCacheWarmer
  19.  *
  20.  * @author  Adam Piotrowski <adam@wellcommerce.org>
  21.  *
  22.  * Created on base of the LiipThemeBundle <https://github.com/liip/LiipThemeBundle>
  23.  *
  24.  * Special thanks goes to its authors and contributors
  25.  */
  26. class TemplatePathsCacheWarmer extends BaseTemplatePathsCacheWarmer
  27. {
  28.     /**
  29.      * @var \WellCommerce\Bundle\AppBundle\Service\Theme\Locator\TemplateLocator
  30.      */
  31.     protected $locator;
  32.     public function warmUp($cacheDir)
  33.     {
  34.         $locator      $this->locator->getLocator();
  35.         $allTemplates $this->finder->findAllTemplates();
  36.         $templates    = [];
  37.         foreach ($allTemplates as $template) {
  38.             $this->locateTemplate($locator$template$templates);
  39.         }
  40.         $this->writeCacheFile($cacheDir '/templates.php'sprintf('<?php return %s;'var_export($templatestrue)));
  41.     }
  42.     public function isOptional()
  43.     {
  44.         return false;
  45.     }
  46.     protected function locateTemplate(FileLocatorInterface $locatorTemplateReference $template, array &$templates)
  47.     {
  48.         $templates[$template->getLogicalName()] = $locator->locate($template->getPath());
  49.     }
  50. }