Skip to content

Commit 76e3537

Browse files
Merge branch '3.2'
* 3.2: Fix getMock usage Remove dead code [Form] DateTimeToLocalizedStringTransformer does not use TZ when using only date [Validator] Fix caching of constraints derived from non-serializable parents [TwigBundle] Fix bug where namespaced paths don't take parent bundles in account [FrameworkBundle] Fix relative paths used as cache keys respect groups when merging constraints fix IPv6 address handling in server commands
2 parents efc49f7 + adfec18 commit 76e3537

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

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
}

Tests/Fixtures/templates.php

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+
);

Tests/Templating/Loader/TemplateLocatorTest.php

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

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

0 commit comments

Comments
 (0)