38 foreach ($attributes as $attribute) {
39 $result[] = $attribute->newInstance();
44 private function getAnnotsOf(\Reflector $reflector, ?
string $annotationType =
null): array {
45 if ($annotationType === null) {
46 return $this->attributesNewInstances($reflector->getAttributes());
48 $annotClass = $this->getAnnotationByKey($annotationType);
49 if (isset($annotClass)) {
50 return $this->attributesNewInstances($reflector->getAttributes($annotClass));
55 public function getAnnotsOfClass(
string $class, ?
string $annotationType =
null): array {
56 return $this->getAnnotsOf(new \ReflectionClass($class), $annotationType);
59 public function getAnnotsOfMethod(
string $class,
string $method, ?
string $annotationType =
null): array {
60 return $this->getAnnotsOf(new \ReflectionMethod($class, $method), $annotationType);
63 public function getAnnotsOfProperty(
string $class,
string $property, ?
string $annotationType =
null): array {
64 return $this->getAnnotsOf(new \ReflectionProperty($class, $property), $annotationType);
67 public function start(
string $cacheDirectory): void {
76 'table' =>
Table::class,
79 'yuml' =>
Yuml::class,
82 'route' =>
Route::class,
84 'post' =>
Post::class,
86 'patch' =>
Patch::class,
90 'rest' =>
Rest::class,
98 return self::$registry[$key] ?? null;
102 self::$registry = \array_merge(self::$registry, $nameClasses);
105 public function getAnnotation(?
object $container,
string $key, array $parameters = []): ?object {
106 if (isset(self::$registry[$key])) {
107 $classname = self::$registry[$key];
108 if (isset($container) && \method_exists($container,
'addUse')) {
109 $container->addUse($classname);
111 $reflect = new \ReflectionClass($classname);
112 return $reflect->newInstanceArgs($parameters);
118 $annotationsStr =
'';
119 $size = \count($annotations);
121 $annotationsStr = $prefix;
122 \array_walk($annotations,
function ($item) {
126 $annotationsStr .=
"\n{$prefix}" . implode(
"\n{$prefix}", $annotations);
128 $annotationsStr .=
"\n{$prefix}" . \end($annotations);
131 return $annotationsStr;
138 public static function isMany(
object $annotation): bool {
150 public function is(
string $key,
object $annotation): bool {
151 $class = self::$registry[$key] ?? null;
152 if ($class !==
null) {
153 return $annotation instanceof $class;
159 self::$registry = \array_merge(self::$registry, [
160 'allow' => \
Ubiquity\attributes\items\acl\Allow::class,
161 'resource' => \
Ubiquity\attributes\items\acl\Resource::class,
162 'permission' => \
Ubiquity\attributes\items\acl\Permission::class
getAnnotsOfClass(string $class, ?string $annotationType=null)
static isOneToMany(object $annotation)
static isMany(object $annotation)
start(string $cacheDirectory)
Start the annotations engine for dev mode.
getAnnotationsStr(array $annotations, string $prefix="\t")
attributesNewInstances(array $attributes)
is(string $key, object $annotation)
getAnnotsOf(\Reflector $reflector, ?string $annotationType=null)
static isManyToMany(object $annotation)
getAnnotationByKey(?string $key=null)
getAnnotation(?object $container, string $key, array $parameters=[])
getAnnotsOfProperty(string $class, string $property, ?string $annotationType=null)
registerAnnotations(array $nameClasses)
static isManyToOne(object $annotation)
getAnnotsOfMethod(string $class, string $method, ?string $annotationType=null)
Attribute for autowiring.
Attribute for dependency injection.
Defines a route with the delete method Ubiquity\attributes\items\router$Post This class is part of Ub...
Defines a route with the get method Ubiquity\attributes\items\router$Get This class is part of Ubiqui...
Defines a route with the options method Ubiquity\attributes\items\router$Options This class is part o...
Defines a route with the patch method Ubiquity\attributes\items\router$Patch This class is part of Ub...
Defines a route with the post method Ubiquity\attributes\items\router$Post This class is part of Ubiq...
Defines a route with the put method Ubiquity\attributes\items\router$Put This class is part of Ubiqui...
Ubiquity\annotations$AnnotationsInterface This class is part of Ubiquity.
Class Configuration \config.