<?php
declare(strict_types=0);
/*
* WellCommerce Foundation
*
* This file is part of the WellCommerce package.
*
* (c) Adam Piotrowski <adam@wellcommerce.org>, Adrian Potepa <adrian@wellcommerce.org>
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code.
*/
namespace WellCommerce\Bundle\AppBundle\CacheWarmer;
use Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplatePathsCacheWarmer as BaseTemplatePathsCacheWarmer;
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
use Symfony\Component\Config\FileLocatorInterface;
/**
* Class TemplatePathsCacheWarmer
*
* @author Adam Piotrowski <adam@wellcommerce.org>
*
* Created on base of the LiipThemeBundle <https://github.com/liip/LiipThemeBundle>
*
* Special thanks goes to its authors and contributors
*/
class TemplatePathsCacheWarmer extends BaseTemplatePathsCacheWarmer
{
/**
* @var \WellCommerce\Bundle\AppBundle\Service\Theme\Locator\TemplateLocator
*/
protected $locator;
public function warmUp($cacheDir)
{
$locator = $this->locator->getLocator();
$allTemplates = $this->finder->findAllTemplates();
$templates = [];
foreach ($allTemplates as $template) {
$this->locateTemplate($locator, $template, $templates);
}
$this->writeCacheFile($cacheDir . '/templates.php', sprintf('<?php return %s;', var_export($templates, true)));
}
public function isOptional()
{
return false;
}
protected function locateTemplate(FileLocatorInterface $locator, TemplateReference $template, array &$templates)
{
$templates[$template->getLogicalName()] = $locator->locate($template->getPath());
}
}