diff --git a/src/Core/Cache/StandardCacheWarmer.php b/src/Core/Cache/StandardCacheWarmer.php index 44878325a..be1a0d1be 100644 --- a/src/Core/Cache/StandardCacheWarmer.php +++ b/src/Core/Cache/StandardCacheWarmer.php @@ -112,30 +112,36 @@ protected function warmupTemplateRootPaths(RenderingContextInterface $renderingC $paths = $renderingContext->getTemplatePaths(); foreach ($this->formats as $format) { $paths->setFormat($format); - foreach ($this->detectControllerNamesInTemplateRootPaths($paths->getTemplateRootPaths()) as $controllerName) { - foreach ($paths->resolveAvailableTemplateFiles($controllerName, $format) as $templateFile) { + $formatCutoffPoint = - (strlen($format) + 1); + foreach ($paths->getTemplateRootPaths() as $templateRootPath) { + $pathCutoffPoint = strlen($templateRootPath); + foreach ($this->detectControllerNamesInTemplateRootPaths([$templateRootPath]) as $controllerName) { + foreach ($paths->resolveAvailableTemplateFiles($controllerName, $format) as $templateFile) { + $state = $this->warmSingleFile( + $templateFile, + $paths->getTemplateIdentifier( + $controllerName, + substr($templateFile, $pathCutoffPoint, $formatCutoffPoint) + ), + $renderingContext + ); + $result->add($state, $templateFile); + } + } + $limitedPaths = clone $paths; + $limitedPaths->setTemplateRootPaths([$templateRootPath]); + foreach ($limitedPaths->resolveAvailableTemplateFiles(null, $format) as $templateFile) { $state = $this->warmSingleFile( $templateFile, $paths->getTemplateIdentifier( - $controllerName, - basename($templateFile, '.' . $format) + 'Default', + substr($templateFile, $pathCutoffPoint, $formatCutoffPoint) ), $renderingContext ); $result->add($state, $templateFile); } } - foreach ($paths->resolveAvailableTemplateFiles(null, $format) as $templateFile) { - $state = $this->warmSingleFile( - $templateFile, - $paths->getTemplateIdentifier( - 'Default', - basename($templateFile, '.' . $format) - ), - $renderingContext - ); - $result->add($state, $templateFile); - } } return $result; } @@ -158,14 +164,20 @@ protected function warmupPartialRootPaths(RenderingContextInterface $renderingCo $result = new FluidCacheWarmupResult(); $paths = $renderingContext->getTemplatePaths(); foreach ($this->formats as $format) { - foreach ($paths->resolveAvailablePartialFiles($format) as $partialFile) { - $paths->setFormat($format); - $state = $this->warmSingleFile( - $partialFile, - $paths->getPartialIdentifier(basename($partialFile, '.' . $format)), - $renderingContext - ); - $result->add($state, $partialFile); + $formatCutoffPoint = - (strlen($format) + 1); + foreach ($paths->getPartialRootPaths() as $partialRootPath) { + $limitedPaths = clone $paths; + $limitedPaths->setPartialRootPaths([$partialRootPath]); + $pathCutoffPoint = strlen($partialRootPath); + foreach ($limitedPaths->resolveAvailablePartialFiles($format) as $partialFile) { + $paths->setFormat($format); + $state = $this->warmSingleFile( + $partialFile, + $paths->getPartialIdentifier(substr($partialFile, $pathCutoffPoint, $formatCutoffPoint)), + $renderingContext + ); + $result->add($state, $partialFile); + } } } return $result; @@ -189,14 +201,20 @@ protected function warmupLayoutRootPaths(RenderingContextInterface $renderingCon $result = new FluidCacheWarmupResult(); $paths = $renderingContext->getTemplatePaths(); foreach ($this->formats as $format) { - foreach ($paths->resolveAvailableLayoutFiles($format) as $layoutFile) { - $paths->setFormat($format); - $state = $this->warmSingleFile( - $layoutFile, - $paths->getLayoutIdentifier(basename($layoutFile, '.' . $layoutFile)), - $renderingContext - ); - $result->add($state, $layoutFile); + $formatCutoffPoint = - (strlen($format) + 1); + foreach ($paths->getLayoutRootPaths() as $layoutRootPath) { + $limitedPaths = clone $paths; + $limitedPaths->setLayoutRootPaths([$layoutRootPath]); + $pathCutoffPoint = strlen($layoutRootPath); + foreach ($limitedPaths->resolveAvailableLayoutFiles($format) as $layoutFile) { + $paths->setFormat($format); + $state = $this->warmSingleFile( + $layoutFile, + $paths->getLayoutIdentifier(substr($layoutFile, $pathCutoffPoint, $formatCutoffPoint)), + $renderingContext + ); + $result->add($state, $layoutFile); + } } } return $result; diff --git a/tests/Unit/Core/Cache/StandardCacheWarmerTest.php b/tests/Unit/Core/Cache/StandardCacheWarmerTest.php index 3052be46b..24c04563a 100644 --- a/tests/Unit/Core/Cache/StandardCacheWarmerTest.php +++ b/tests/Unit/Core/Cache/StandardCacheWarmerTest.php @@ -34,10 +34,10 @@ public function testWarm() $subject = $this->getMockBuilder(StandardCacheWarmer::class) ->setMethods(['warmSingleFile', 'detectControllerNamesInTemplateRootPaths']) ->getMock(); - $subject->expects($this->exactly(7)) + $subject->expects($this->atLeastOnce()) ->method('detectControllerNamesInTemplateRootPaths') ->willReturn(['Default', 'Standard']); - $subject->expects($this->exactly(70)) + $subject->expects($this->atLeastOnce()) ->method('warmSingleFile') ->willReturn($failedCompilingState); $context = new RenderingContextFixture(); @@ -47,20 +47,26 @@ public function testWarm() 'resolveAvailableTemplateFiles', 'resolveAvailablePartialFiles', 'resolveAvailableLayoutFiles', - 'resolveFileInPaths' + 'resolveFileInPaths', + 'getTemplateRootPaths', + 'getPartialRootPaths', + 'getLayoutRootPaths', ] ) ->getMock(); - $paths->expects($this->exactly(21)) + $paths->expects($this->atLeastOnce()) ->method('resolveAvailableTemplateFiles') ->willReturn(['foo', 'bar']); - $paths->expects($this->exactly(7)) + $paths->expects($this->atLeastOnce()) ->method('resolveAvailablePartialFiles') ->willReturn(['foo', 'bar']); - $paths->expects($this->exactly(7)) + $paths->expects($this->atLeastOnce()) ->method('resolveAvailableLayoutFiles') ->willReturn(['foo', 'bar']); - $paths->expects($this->exactly(56))->method('resolveFileInPaths')->willReturn('/dev/null'); + $paths->expects($this->atLeastOnce())->method('resolveFileInPaths')->willReturn('/dev/null'); + $paths->expects($this->atLeastOnce())->method('getTemplateRootPaths')->willReturn(['/dev/null']); + $paths->expects($this->atLeastOnce())->method('getPartialRootPaths')->willReturn(['/dev/null']); + $paths->expects($this->atLeastOnce())->method('getLayoutRootPaths')->willReturn(['/dev/null']); $compiler = $this->getMockBuilder(TemplateCompiler::class) ->setMethods(['enterWarmupMode']) ->getMock();