mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-24 02:46:24 +00:00
CoreExtension::getAttribute: small improvement regarding getter/isser/hasser
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user