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 @@ -253,7 +253,7 @@ function (ChildDefinition $definition, AsLiveComponent $attribute) {
;

$container->register('ux.live_component.twig.template_mapper', TemplateMap::class)
->setArguments(['%kernel.cache_dir%/'.self::TEMPLATES_MAP_FILENAME]);
->setArguments(['%kernel.build_dir%/'.self::TEMPLATES_MAP_FILENAME]);

$container->register('ux.live_component.twig.cache_warmer', TemplateCacheWarmer::class)
->setArguments([
Expand Down
3 changes: 2 additions & 1 deletion src/LiveComponent/src/Twig/TemplateCacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public function warmUp(string $cacheDir, ?string $buildDir = null): array
$map[hash('xxh128', $item.$this->secret)] = $item;
}

(new PhpArrayAdapter($cacheDir.'/'.$this->cacheFilename, new NullAdapter()))->warmUp(['map' => $map]);
$cacheFile = sprintf('%s%s%s', $buildDir ?? $cacheDir, DIRECTORY_SEPARATOR, $this->cacheFilename);
PhpArrayAdapter::create($cacheFile, new NullAdapter())->warmUp(['map' => $map]);

return [];
}
Expand Down
8 changes: 5 additions & 3 deletions src/LiveComponent/src/Twig/TemplateMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
*/
final class TemplateMap
{
/**
* @var array<string, string> Map of <obscured name> => <template name>
*/
private readonly array $map;

public function __construct(string $cacheFile)
{
$this->map = (new PhpArrayAdapter($cacheFile, new NullAdapter()))->getItem('map')->get();
$this->map = PhpArrayAdapter::create($cacheFile, new NullAdapter())->getItem('map')->get();
}

public function resolve(string $obscuredName): string
Expand All @@ -35,8 +38,7 @@ public function resolve(string $obscuredName): string

public function obscuredName(string $templateName): string
{
$obscuredName = array_search($templateName, $this->map, true);
if (false === $obscuredName) {
if (false === $obscuredName = array_search($templateName, $this->map, true)) {
throw new \RuntimeException(sprintf('Cannot find a match for template "%s". Cache may be corrupt.', $templateName));
}

Expand Down