8000 [FrameworkBundle] Fix relative paths used as cache keys by nicolas-grekas · Pull Request #21237 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Merged
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 @@ -24,6 +24,8 @@ class TemplateLocator implements FileLocatorInterface
protected $locator;
protected $cache;

private $cacheHits = array();

/**
* Constructor.
*
Expand Down Expand Up @@ -71,12 +73,15 @@ public function locate($template, $currentPath = null, $first = true)

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

if (isset($this->cacheHits[$key])) {
return $this->cacheHits[$key];
}
if (isset($this->cache[$key])) {
return $this->cache[$key];
return $this->cacheHits[$key] = realpath($this->cache[$key]) ?: $this->cache[$key];
}

try {
return $this->cache[$key] = $this->locator->locate($template->getPath(), $currentPath);
return $this->cacheHits[$key] = $this->locator->locate($template->getPath(), $currentPath);
} catch (\InvalidArgumentException $e) {
throw new \InvalidArgumentException(sprintf('Unable to find template "%s" : "%s".', $template, $e->getMessage()), 0, $e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return array(
'bundle:controller:name.format.engine' => __DIR__.'/../Fixtures/Resources/views/this.is.a.template.format.engine',
);
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ public function testLocateATemplate()
$this->assertEquals('/path/to/template', $locator->locate($template));
}

public function testLocateATemplateFromCacheDir()
{
$template = new TemplateReference('bundle', 'controller', 'name', 'format', 'engine');

$fileLocator = $this->getFileLocator();

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

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

public function testThrowsExceptionWhenTemplateNotFound()
{
$template = new TemplateReference('bundle', 'controller', 'name', 'format', 'engine');
Expand Down
0