Skip to content

Commit 3f5d785

Browse files
committed
[TwigComponent] Fix #3195
This fixes the issue that when relying on the classMap, even components with classes would be loaded as anonymous components, because loading an anonymous template was tried before even checking the classMap. This fixes the issue by resolving the class map right at the beginning, if possible. This also allows us to reuse the code that loads the metadata: As we make sure `$name` holds the real config key right at the beginning, we don't have to care anymore about whether the caller provided the internal config key or a class name. The special case for class names can go. As a side effect, we get a much better error message when attempting to load using an FQCN, because of the code reuse.
1 parent 173db46 commit 3f5d785

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/TwigComponent/src/ComponentFactory.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public function __construct(
4646

4747
public function metadataFor(string $name): ComponentMetadata
4848
{
49+
$name = $this->classMap[$name] ?? $name;
50+
4951
if ($config = $this->config[$name] ?? null) {
5052
return new ComponentMetadata($config);
5153
}
@@ -59,14 +61,6 @@ public function metadataFor(string $name): ComponentMetadata
5961
return new ComponentMetadata($this->config[$name]);
6062
}
6163

62-
if ($mappedName = $this->classMap[$name] ?? null) {
63-
if ($config = $this->config[$mappedName] ?? null) {
64-
return new ComponentMetadata($config);
65-
}
66-
67-
throw new \InvalidArgumentException(\sprintf('Unknown component "%s".', $name));
68-
}
69-
7064
$this->throwUnknownComponentException($name);
7165
}
7266

0 commit comments

Comments
 (0)