- getAttribute() can now query multiple types

This commit is contained in:
Dave Mc Nicoll committed 2024-05-31 12:28:00 +00:00
1 parent 0cdc2dc3d8
commit 19c79d0374
2 files changed
+6 -11

No files matched your search

+6 -10
View File
@@ -56,16 +56,18 @@ abstract class Reflected
}
}
public function getAttributes(?string $attributeType = null): array
public function getAttributes(null|string|array $attributeType = null): array
{
if ($attributeType) {
$list = [];
foreach($this->attributes as $attribute) {
if ($attribute->object instanceof $attributeType) {
foreach((array) $attributeType as $type) {
if ($attribute->object instanceof $type) {
$list[] = $attribute;
}
}
}
return $list;
}
@@ -73,14 +75,8 @@ abstract class Reflected
return $this->attributes;
}
public function getAttribute(string $attributeType): ?object
public function getAttribute(string|array $attributeType): ?object
{
foreach($this->getAttributes($attributeType) as $attribute) {
if ($attribute->object instanceof $attributeType) {
return $attribute;
}
}
return null;
return $this->getAttributes($attributeType)[0] ?? null;
}
}
-1
View File
@@ -22,7 +22,6 @@ class ReflectedClass implements ReflectedInterface
public function getProperties(bool $deep = true) : array
{
return $deep ? array_replace(
# $this->parent ? $this->parent->getProperties(true) : [],
$this->parent ? $this->parent->getProperties(true) : [],
$this->properties
) : $this->properties;