diff --git a/src/Common/Reflected.php b/src/Common/Reflected.php index f555268..a55893a 100644 --- a/src/Common/Reflected.php +++ b/src/Common/Reflected.php @@ -69,10 +69,10 @@ abstract class Reflected } } - return $list; + return array_reverse($list); } - return $this->attributes; + return array_reverse($this->attributes); } public function getAttribute(string|array $attributeType): ?object diff --git a/src/Common/ReflectedClass.php b/src/Common/ReflectedClass.php index dff3e02..9d84c61 100644 --- a/src/Common/ReflectedClass.php +++ b/src/Common/ReflectedClass.php @@ -39,12 +39,17 @@ class ReflectedClass implements ReflectedInterface ) : $this->methods; } - public function getAttributes(bool $deep = true, ?string $attributeType = null) : array + public function getAttributes(bool $deep = true, ? string $attributeType = null) : array + { + return array_reverse($this->getOrderedAttributes($deep, $attributeType)); + } + + protected function getOrderedAttributes(bool $deep = true, ? string $attributeType = null) : array { $attributes = $deep ? array_merge( - $this->parent ? $this->parent->getAttributes(true) : [], - array_merge(...array_map(fn($e) => $e->getAttributes(true), $this->interfaces)), - array_merge(...array_map(fn($e) => $e->getAttributes(true), $this->traits)), + $this->parent ? $this->parent->getOrderedAttributes(true) : [], + array_merge(...array_map(fn($e) => $e->getOrderedAttributes(true), $this->interfaces)), + array_merge(...array_map(fn($e) => $e->getOrderedAttributes(true), $this->traits)), $this->attributes ) : $this->attributes; @@ -167,7 +172,7 @@ class ReflectedClass implements ReflectedInterface public function getAttribute(string $attributeType): ?object { - foreach($this->getAttributes($attributeType) as $attribute) { + foreach($this->getAttributes(true, $attributeType) as $attribute) { if ($attribute->object instanceof $attributeType) { return $attribute; } diff --git a/src/Route/RouteFetcher.php b/src/Route/RouteFetcher.php index 5fbe254..a635b0e 100644 --- a/src/Route/RouteFetcher.php +++ b/src/Route/RouteFetcher.php @@ -99,7 +99,7 @@ class RouteFetcher { $objects = $objectResolver->reflectedClass->getClassAttributeListFromClassname($attributes['object'], true, false); - foreach(array_reverse($objects) as $object) { + foreach($objects as $object) { if ($object->method ?? false ) { $methods ??= (array) $object->method; } diff --git a/src/Security/SecurityHandler.php b/src/Security/SecurityHandler.php index 5af6884..b41d182 100644 --- a/src/Security/SecurityHandler.php +++ b/src/Security/SecurityHandler.php @@ -34,7 +34,7 @@ class SecurityHandler { { # Searching method first and fallbacking on object if none found if ( $list = $this->findAttributes(Attribute\Security::class, $className, $methodName) ) { - return array_pop($list)->locked; + return array_shift($list)->locked; } return true;