diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php index d210dd66f839..9de031934e3c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php @@ -55,10 +55,20 @@ public function locate($template, $currentPath = null, $first = true) { $key = $template->getSignature(); - if (!isset($this->templates[$key])) { - return parent::locate($template, $currentPath, $first); - } + $path = $this->getCachedTemplatePath($key); + + return $path === null ? parent::locate($template) : $path; + } - return $this->templates[$key]; + /** + * Returns the template path from the cache + * + * @param string $key The template signature + * + * @return string|null The path when it is present in the call, false otherwise + */ + protected function getCachedTemplatePath($key) + { + return isset($this->templates[$key]) ? $this->templates[$key] : null; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/CachedTemplateLocatorTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/CachedTemplateLocatorTest.php new file mode 100644 index 000000000000..ccbc2fc50276 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/CachedTemplateLocatorTest.php @@ -0,0 +1,41 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Tests\Templating\Loader; + +use Symfony\Bundle\FrameworkBundle\Templating\Loader\CachedTemplateLocator; +use Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator; +use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference; +use Symfony\Bundle\FrameworkBundle\Tests\TestCase; + +class CachedTemplateLocatorTest extends TestCase +{ + public function testLocateACachedTemplate() + { + $template = new TemplateReference('bundle', 'controller', 'name', 'format', 'engine'); + + $locator = $this + ->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\Loader\CachedTemplateLocator') + ->setMethods(array('getCachedTemplatePath')) + ->disableOriginalConstructor() + ->getMock() + ; + + $locator + ->expects($this->once()) + ->method('getCachedTemplatePath') + ->with($template->getSignature()) + ->will($this->returnValue('/cached/path/to/template')) + ; + + $this->assertEquals('/cached/path/to/template', $locator->locate($template)); + } +}