Skip to content

Commit 53bebd7

Browse files
committed
AttributesEngine improvement (getAnnotsOf added)
1 parent a7f0c6d commit 53bebd7

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

src/Ubiquity/attributes/AttributesEngine.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,27 @@ protected function attributesNewInstances(array $attributes): array {
4040
return $result;
4141
}
4242

43-
public function getAnnotsOfClass(string $class, ?string $annotationType = null): array {
44-
$reflect = new \ReflectionClass($class);
43+
private function getAnnotsOf(\Reflector $reflector, ?string $annotationType = null): array {
44+
if ($annotationType === null) {
45+
return $this->attributesNewInstances($reflector->getAttributes());
46+
}
4547
$annotClass = $this->getAnnotationByKey($annotationType);
4648
if (isset($annotClass)) {
47-
return $this->attributesNewInstances($reflect->getAttributes($annotClass));
49+
return $this->attributesNewInstances($reflector->getAttributes($annotClass));
4850
}
4951
return [];
5052
}
5153

54+
public function getAnnotsOfClass(string $class, ?string $annotationType = null): array {
55+
return $this->getAnnotsOf(new \ReflectionClass($class), $annotationType);
56+
}
57+
5258
public function getAnnotsOfMethod(string $class, string $method, ?string $annotationType = null): array {
53-
$reflect = new \ReflectionMethod($class, $method);
54-
$annotClass = $this->getAnnotationByKey($annotationType);
55-
if (isset($annotClass)) {
56-
return $this->attributesNewInstances($reflect->getAttributes($annotClass));
57-
}
58-
return [];
59+
return $this->getAnnotsOf(new \ReflectionMethod($class, $method), $annotationType);
5960
}
6061

6162
public function getAnnotsOfProperty(string $class, string $property, ?string $annotationType = null): array {
62-
$reflect = new \ReflectionProperty($class, $property);
63-
$annotClass = $this->getAnnotationByKey($annotationType);
64-
if (isset($annotClass)) {
65-
return $this->attributesNewInstances($reflect->getAttributes($annotClass));
66-
}
67-
return [];
63+
return $this->getAnnotsOf(new \ReflectionProperty($class, $property), $annotationType);
6864
}
6965

7066
public function start(string $cacheDirectory): void {
@@ -157,4 +153,3 @@ public function registerAcls(): void {
157153
]);
158154
}
159155
}
160-

0 commit comments

Comments
 (0)