8000 [FrameworkBundle] Fix relative paths used as cache keys · symfony/symfony@5441e9b · GitHub
[go: up one dir, main page]

Skip to content

Commit 5441e9b

Browse files
[FrameworkBundle] Fix relative paths used as cache keys
1 parent f83ad56 commit 5441e9b

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class TemplateLocator implements FileLocatorInterface
2424
protected $locator;
2525
protected $cache;
2626

27+
private $cacheHits = array();
28+
2729
/**
2830
* Constructor.
2931
*
@@ -71,12 +73,15 @@ public function locate($template, $currentPath = null, $first = true)
7173

7274
$key = $this->getCacheKey($template);
7375

76+
if (isset($this->cacheHits[$key])) {
77+
return $this->cacheHits[$key];
78+
}
7479
if (isset($this->cache[$key])) {
75-
return $this->cache[$key];
80+
return $this->cacheHits[$key] = realpath($this->cache[$key]) ?: $this->cache[$key];
7681
}
7782

7883
try {
79-
return $this->cache[$key] = $this->locator->locate($template->getPath(), $currentPath);
84+
return $this->cacheHits[$key] = $this->locator->locate($template->getPath(), $currentPath);
8085
} catch (\InvalidArgumentException $e) {
8186
throw new \InvalidArgumentException(sprintf('Unable to find template "%s" : "%s".', $template, $e->getMessage()), 0, $e);
8287
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return array(
4+
'bundle:controller:name.format.engine' => __DIR__.'/../Fixtures/Resources/views/this.is.a.template.format.engine',
5+
);

src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/TemplateLocatorTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ public function testLocateATemplate()
3535
$this->assertEquals('/path/to/template', $locator->locate($template));
3636
}
3737

38+
public function testLocateATemplateFromCacheDir()
39+
{
40+
$template = new TemplateReference('bundle', 'controller', 'name', 'format', 'engine');
41+
42+
$fileLocator = $this->getFileLocator();
43+
44+
$locator = new TemplateLocator($fileLocator, __DIR__.'/../../Fixtures');
45+
46+
$this->assertEquals(realpath(__DIR__.'/../../Fixtures/Resources/views/this.is.a.template.format.engine'), $locator->locate($template));
47+
}
48+
3849
public function testThrowsExceptionWhenTemplateNotFound()
3950
{
4051
$template = new TemplateReference('bundle', 'controller', 'name', 'format', 'engine');

0 commit comments

Comments
 (0)
0