CoreExtension::getAttribute: small improvement regarding getter/isser/hasser

This commit is contained in:
Gregor Harlan
2025-07-05 11:50:32 +02:00
parent b1d2a9c20f
commit 45cd6ffe80
+11 -8
View File
@@ -1830,14 +1830,14 @@ final class CoreExtension extends AbstractExtension
$classCache[$lcName = $lcMethods[$i]] = $method;
if ('g' === $lcName[0] && str_starts_with($lcName, 'get')) {
$name = substr($method, 3);
$lcName = substr($lcName, 3);
$prefixLength = 3;
$lcName = substr($lcName, $prefixLength);
} elseif ('i' === $lcName[0] && str_starts_with($lcName, 'is')) {
$name = substr($method, 2);
$lcName = substr($lcName, 2);
$prefixLength = 2;
$lcName = substr($lcName, $prefixLength);
} elseif ('h' === $lcName[0] && str_starts_with($lcName, 'has')) {
$name = substr($method, 3);
$lcName = substr($lcName, 3);
$prefixLength = 3;
$lcName = substr($lcName, $prefixLength);
if (\in_array('is'.$lcName, $lcMethods, true)) {
continue;
}
@@ -1845,8 +1845,11 @@ final class CoreExtension extends AbstractExtension
continue;
}
// skip get() and is() methods (in which case, $name is empty)
if ($name) {
// skip get(), is() and has() methods (in which case, $lcName is empty)
if ($lcName) {
// camelCase name (e.g. getFooBar() -> fooBar)
$name = $lcName[0].substr($method, $prefixLength + 1);
if (!isset($classCache[$name])) {
$classCache[$name] = $method;
}