From 19c79d037402b09418ea2361a9081e402be346e2 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Fri, 31 May 2024 12:28:00 +0000 Subject: [PATCH] - getAttribute() can now query multiple types --- src/Common/Reflected.php | 18 +++++++----------- src/Common/ReflectedClass.php | 1 - 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/Common/Reflected.php b/src/Common/Reflected.php index d776602..f555268 100644 --- a/src/Common/Reflected.php +++ b/src/Common/Reflected.php @@ -56,14 +56,16 @@ 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) { - $list[] = $attribute; + foreach((array) $attributeType as $type) { + if ($attribute->object instanceof $type) { + $list[] = $attribute; + } } } @@ -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; } } \ No newline at end of file diff --git a/src/Common/ReflectedClass.php b/src/Common/ReflectedClass.php index 05a7842..dff3e02 100644 --- a/src/Common/ReflectedClass.php +++ b/src/Common/ReflectedClass.php @@ -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;