[TwigBundle] simplified code

This commit is contained in:
Fabien Potencier 2019-03-19 18:07:46 +01:00
parent bff9e68bb4
commit 4d6967e756

View File

@ -16,7 +16,6 @@ use Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinderInterface;
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface; use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
use Symfony\Component\Templating\TemplateReference;
use Twig\Environment; use Twig\Environment;
use Twig\Error\Error; use Twig\Error\Error;
@ -69,10 +68,6 @@ class TemplateCacheCacheWarmer implements CacheWarmerInterface, ServiceSubscribe
} }
foreach ($templates as $template) { foreach ($templates as $template) {
if ('twig' !== $template->get('engine')) {
continue;
}
try { try {
$twig->loadTemplate($template); $twig->loadTemplate($template);
} catch (Error $e) { } catch (Error $e) {
@ -107,7 +102,7 @@ class TemplateCacheCacheWarmer implements CacheWarmerInterface, ServiceSubscribe
* @param string $namespace The namespace for these templates * @param string $namespace The namespace for these templates
* @param string $dir The folder where to look for templates * @param string $dir The folder where to look for templates
* *
* @return array An array of templates of type TemplateReferenceInterface * @return array An array of templates
*/ */
private function findTemplatesInFolder($namespace, $dir) private function findTemplatesInFolder($namespace, $dir)
{ {
@ -120,10 +115,7 @@ class TemplateCacheCacheWarmer implements CacheWarmerInterface, ServiceSubscribe
foreach ($finder->files()->followLinks()->in($dir) as $file) { foreach ($finder->files()->followLinks()->in($dir) as $file) {
$name = $file->getRelativePathname(); $name = $file->getRelativePathname();
$templates[] = new TemplateReference( $templates[] = $namespace ? sprintf('@%s/%s', $namespace, $name) : $name;
$namespace ? sprintf('@%s/%s', $namespace, $name) : $name,
'twig'
);
} }
return $templates; return $templates;