- getAttribute() can now query multiple types
This commit is contained in:
parent
0cdc2dc3d8
commit
19c79d0374
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue