Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[FrameworkBundle] Cache warmer skips global templates #28589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,26 @@ public function findAllTemplates()
$templates = array_merge($templates, $this->findTemplatesInBundle($bundle));
}

$templates = array_merge($templates, $this->findTemplatesInFolder($this->rootDir.'/views'));
$templates = array_merge($templates, $this->findTemplatesInFolder($this->rootDir, 'bundles'));

return $this->templates = $templates;
}

/**
* Find templates in the given directory.
*
* @param string $dir The folder where to look for templates
* @param string $dir The folder where to look for templates
* @param string $excludeDir A subfolder of $folder to exclude
*
* @return TemplateReferenceInterface[]
*/
private function findTemplatesInFolder($dir)
private function findTemplatesInFolder($dir, $excludeDir = null)
{
$templates = array();

if (is_dir($dir)) {
$finder = new Finder();
foreach ($finder->files()->followLinks()->in($dir) as $file) {
foreach ($finder->files()->followLinks()->in($dir)->exclude($excludeDir) as $file) {
$template = $this->parser->parse($file->getRelativePathname());
if (false !== $template) {
$templates[] = $template;
Expand All @@ -99,7 +100,7 @@ private function findTemplatesInBundle(BundleInterface $bundle)
$name = $bundle->getName();
$templates = array_unique(array_merge(
$this->findTemplatesInFolder($bundle->getPath().'/Resources/views'),
$this->findTemplatesInFolder($this->rootDir.'/'.$name.'/views')
$this->findTemplatesInFolder($this->rootDir.'/bundles/'.$name)
));

foreach ($templates as $i => $template) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@

<service id="file_locator" class="Symfony\Component\HttpKernel\Config\FileLocator">
<argument type="service" id="kernel" />
<argument>%kernel.root_dir%/Resources</argument>
<argument>%kernel.project_dir%/src/Resources</argument>
<argument type="collection">
<argument>%kernel.root_dir%</argument>
<argument>%kernel.project_dir%</argument>
</argument>
</service>
<service id="Symfony\Component\HttpKernel\Config\FileLocator" alias="file_locator" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<service id="templating.finder" class="Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinder">
<argument type="service" id="kernel" />
<argument type="service" id="templating.filename_parser" />
<argument>%kernel.root_dir%/Resources</argument>
<argument>%kernel.project_dir%/templates</argument>
</service>

<service id="templating.cache_warmer.template_paths" class="Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplatePathsCacheWarmer">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function getPath()

$path = (empty($controller) ? '' : $controller.'/').$this->get('name').'.'.$this->get('format').'.'.$this->get('engine');

return empty($this->parameters['bundle']) ? 'views/'.$path : '@'.$this->get('bundle').'/Resources/views/'.$path;
return empty($this->parameters['bundle']) ? 'templates/'.$path : '@'.$this->get('bundle').'/Resources/views/'.$path;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testFindAllTemplates()

$parser = new TemplateFilenameParser();

$finder = new TemplateFinder($kernel, $parser, __DIR__.'/../Fixtures/Resources');
$finder = new TemplateFinder($kernel, $parser, __DIR__.'/../Fixtures/Resources/templates');

$templates = array_map(
function ($template) { return $template->getLogicalName(); },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
This template is used for translation message extraction tests
<?php echo $view['translator']->trans('single-quoted key') ?>
<?php echo $view['translator']->trans('double-quoted key') ?>
<?php echo $view['translator']->trans('single-quoted key'); ?>
<?php echo $view['translator']->trans('double-quoted key'); ?>
<?php echo $view['translator']->trans(<<<'EOF'
heredoc key
EOF
) ?>
); ?>
<?php echo $view['translator']->trans(<<<'EOF'
nowdoc key
EOF
) ?>
); ?>
<?php echo $view['translator']->trans(
"double-quoted key with whitespace and escaped \$\n\" sequences"
) ?>
); ?>
<?php echo $view['translator']->trans(
'single-quoted key with whitespace and nonescaped \$\n\' sequences'
) ?>
); ?>
<?php echo $view['translator']->trans(<<<EOF
heredoc key with whitespace and escaped \$\n sequences
EOF
) ?>
); ?>
<?php echo $view['translator']->trans(<<<'EOF'
nowdoc key with whitespace and nonescaped \$\n sequences
EOF
) ?>
); ?>

<?php echo $view['translator']->trans('single-quoted key with "quote mark at the end"') ?>
<?php echo $view['translator']->trans('single-quoted key with "quote mark at the end"'); ?>

<?php echo $view['translator']->transChoice(
'{0} There is no apples|{1} There is one apple|]1,Inf[ There are %count% apples',
10,
array('%count%' => 10)
) ?>
); ?>

<?php echo $view['translator']->trans('other-domain-test-no-params-short-array', array(), 'not_messages'); ?>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

return array(
'bundle:controller:name.format.engine' => __DIR__.'/../Fixtures/Resources/views/this.is.a.template.format.engine',
'bundle:controller:name.format.engine' => __DIR__.'/../Fixtures/Resources/templates/this.is.a.template.format.engine',
);
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public function registerBundles()
return include $filename;
}

public function getProjectDir()
{
return \dirname(__DIR__);
}

public function getRootDir()
{
return __DIR__;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php echo $this->get('actions')->render($this->get('actions')->controller('Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\FragmentController::inlinedAction', array(
'options' => array(
'bar' => $bar,
'eleven' => 11,
),
)));
?>--<?php
echo $this->get('actions')->render($this->get('actions')->controller('Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\FragmentController::customformatAction', array('_format' => 'html')));
?>--<?php
echo $this->get('actions')->render($this->get('actions')->controller('Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\FragmentController::customlocaleAction', array('_locale' => 'es')));
?>--<?php
$app->getRequest()->setLocale('fr');
echo $this->get('actions')->render($this->get('actions')->controller('Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\FragmentController::forwardlocaleAction'));
?>
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testLocateATemplateFromCacheDir()

$locator = new TemplateLocator($fileLocator, __DIR__.'/../../Fixtures');

$this->assertEquals(realpath(__DIR__.'/../../Fixtures/Resources/views/this.is.a.template.format.engine'), $locator->locate($template));
$this->assertEquals(realpath(__DIR__.'/../../Fixtures/Resources/templates/this.is.a.template.format.engine'), $locator->locate($template));
}

public function testThrowsExceptionWhenTemplateNotFound()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ public function parseProvider()
array('FooBundle:Post:index.xml.php', 'FooBundle:Post:index.xml.php', '@FooBundle/Resources/views/Post/index.xml.php', new TemplateReference('FooBundle', 'Post', 'index', 'xml', 'php')),
array('SensioFooBundle:Post:index.html.php', 'SensioFooBundle:Post:index.html.php', '@SensioFooBundle/Resources/views/Post/index.html.php', new TemplateReference('SensioFooBundle', 'Post', 'index', 'html', 'php')),
array('SensioCmsFooBundle:Post:index.html.php', 'SensioCmsFooBundle:Post:index.html.php', '@SensioCmsFooBundle/Resources/views/Post/index.html.php', new TemplateReference('SensioCmsFooBundle', 'Post', 'index', 'html', 'php')),
array(':Post:index.html.php', ':Post:index.html.php', 'views/Post/index.html.php', new TemplateReference('', 'Post', 'index', 'html', 'php')),
array('::index.html.php', '::index.html.php', 'views/index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
array('index.html.php', '::index.html.php', 'views/index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
array(':Post:index.html.php', ':Post:index.html.php', 'templates/Post/index.html.php', new TemplateReference('', 'Post', 'index', 'html', 'php')),
array('::index.html.php', '::index.html.php', 'templates/index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
array('index.html.php', '::index.html.php', 'templates/index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
array('FooBundle:Post:foo.bar.index.html.php', 'FooBundle:Post:foo.bar.index.html.php', '@FooBundle/Resources/views/Post/foo.bar.index.html.php', new TemplateReference('FooBundle', 'Post', 'foo.bar.index', 'html', 'php')),
array('@FooBundle/Resources/views/layout.html.twig', '@FooBundle/Resources/views/layout.html.twig', '@FooBundle/Resources/views/layout.html.twig', new BaseTemplateReference('@FooBundle/Resources/views/layout.html.twig', 'twig')),
array('@FooBundle/Foo/layout.html.twig', '@FooBundle/Foo/layout.html.twig', '@FooBundle/Foo/layout.html.twig', new BaseTemplateReference('@FooBundle/Foo/layout.html.twig', 'twig')),
array('name.twig', 'name.twig', 'name.twig', new BaseTemplateReference('name.twig', 'twig')),
array('name', 'name', 'name', new BaseTemplateReference('name')),
array('default/index.html.php', '::default/index.html.php', 'views/default/index.html.php', new TemplateReference(null, null, 'default/index', 'html', 'php')),
array('default/index.html.php', '::default/index.html.php', 'templates/default/index.html.php', new TemplateReference(null, null, 'default/index', 'html', 'php')),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public function getTemplateToPathProvider()
return array(
array(new TemplateReference('FooBundle', 'Post', 'index', 'html', 'php'), '@FooBundle/Resources/views/Post/index.html.php'),
array(new TemplateReference('FooBundle', '', 'index', 'html', 'twig'), '@FooBundle/Resources/views/index.html.twig'),
array(new TemplateReference('', 'Post', 'index', 'html', 'php'), 'views/Post/index.html.php'),
array(new TemplateReference('', '', 'index', 'html', 'php'), 'views/index.html.php'),
array(new TemplateReference('', 'Post', 'index', 'html', 'php'), 'templates/Post/index.html.php'),
array(new TemplateReference('', '', 'index', 'html', 'php'), 'templates/index.html.php'),
);
}
}