- getAttribute() can now query multiple types
This commit is contained in:
parent
0cdc2dc3d8
commit
19c79d0374
|
@ -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) {
|
if ($attributeType) {
|
||||||
$list = [];
|
$list = [];
|
||||||
|
|
||||||
foreach($this->attributes as $attribute) {
|
foreach($this->attributes as $attribute) {
|
||||||
if ($attribute->object instanceof $attributeType) {
|
foreach((array) $attributeType as $type) {
|
||||||
$list[] = $attribute;
|
if ($attribute->object instanceof $type) {
|
||||||
|
$list[] = $attribute;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,14 +75,8 @@ abstract class Reflected
|
||||||
return $this->attributes;
|
return $this->attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAttribute(string $attributeType): ?object
|
public function getAttribute(string|array $attributeType): ?object
|
||||||
{
|
{
|
||||||
foreach($this->getAttributes($attributeType) as $attribute) {
|
return $this->getAttributes($attributeType)[0] ?? null;
|
||||||
if ($attribute->object instanceof $attributeType) {
|
|
||||||
return $attribute;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -22,7 +22,6 @@ class ReflectedClass implements ReflectedInterface
|
||||||
public function getProperties(bool $deep = true) : array
|
public function getProperties(bool $deep = true) : array
|
||||||
{
|
{
|
||||||
return $deep ? array_replace(
|
return $deep ? array_replace(
|
||||||
# $this->parent ? $this->parent->getProperties(true) : [],
|
|
||||||
$this->parent ? $this->parent->getProperties(true) : [],
|
$this->parent ? $this->parent->getProperties(true) : [],
|
||||||
$this->properties
|
$this->properties
|
||||||
) : $this->properties;
|
) : $this->properties;
|
||||||
|
|
Loading…
Reference in New Issue