Skip to content

Commit

Permalink
ClassReflection - hasPropertyCache
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Feb 14, 2025
1 parent 2ee974e commit 73d7b88
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/Reflection/ClassReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ final class ClassReflection
/** @var array<string, bool> */
private array $hasMethodCache = [];

/** @var array<string, bool> */
private array $hasPropertyCache = [];

/**
* @param PropertiesClassReflectionExtension[] $propertiesClassReflectionExtensions
* @param MethodsClassReflectionExtension[] $methodsClassReflectionExtensions
Expand Down Expand Up @@ -454,24 +457,28 @@ private function allowsDynamicPropertiesExtensions(): bool

public function hasProperty(string $propertyName): bool
{
if (array_key_exists($propertyName, $this->hasPropertyCache)) {
return $this->hasPropertyCache[$propertyName];
}

if ($this->isEnum()) {
return $this->hasNativeProperty($propertyName);
return $this->hasPropertyCache[$propertyName] = $this->hasNativeProperty($propertyName);
}

foreach ($this->propertiesClassReflectionExtensions as $i => $extension) {
if ($i > 0 && !$this->allowsDynamicPropertiesExtensions()) {
break;
}
if ($extension->hasProperty($this, $propertyName)) {
return true;
return $this->hasPropertyCache[$propertyName] = true;
}
}

if ($this->requireExtendsPropertiesClassReflectionExtension->hasProperty($this, $propertyName)) {
return true;
return $this->hasPropertyCache[$propertyName] = true;
}

return false;
return $this->hasPropertyCache[$propertyName] = false;
}

public function hasMethod(string $methodName): bool
Expand Down

0 comments on commit 73d7b88

Please sign in to comment.