minor #30608 [TwigBundle] Simplify code (fabpot)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[TwigBundle] Simplify code

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

<!--
Write a short README entry for your feature/bugfix here (replace this comment block.)
This will help people understand your PR and can be used as a start of the Doc PR.
Additionally:
 - Bug fixes must be submitted against the lowest branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against the master branch.
-->

Commits
-------

4d6967e756 [TwigBundle] simplified code
This commit is contained in:
Fabien Potencier 2019-03-19 18:22:55 +01:00
commit b315c638d5

View File

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