7use mindplay\annotations\AnnotationCache;
8use mindplay\annotations\AnnotationManager;
9use mindplay\annotations\Annotations;
19 public function start(
string $cacheDirectory): void {
21 'id' =>
'Ubiquity\annotations\items\IdAnnotation',
22 'manyToOne' =>
'Ubiquity\annotations\items\ManyToOneAnnotation',
23 'oneToMany' =>
'Ubiquity\annotations\items\OneToManyAnnotation',
24 'manyToMany' =>
'Ubiquity\annotations\items\ManyToManyAnnotation',
25 'joinColumn' =>
'Ubiquity\annotations\items\JoinColumnAnnotation',
26 'table' =>
'Ubiquity\annotations\items\TableAnnotation',
27 'database' =>
'Ubiquity\annotations\items\DatabaseAnnotation',
28 'transient' =>
'Ubiquity\annotations\items\TransientAnnotation',
29 'column' =>
'Ubiquity\annotations\items\ColumnAnnotation',
30 'validator' =>
'Ubiquity\annotations\items\ValidatorAnnotation',
31 'transformer' =>
'Ubiquity\annotations\items\TransformerAnnotation',
32 'joinTable' =>
'Ubiquity\annotations\items\JoinTableAnnotation',
33 'requestMapping' =>
'Ubiquity\annotations\items\router\RouteAnnotation',
34 'route' =>
'Ubiquity\annotations\items\router\RouteAnnotation',
35 'get' =>
'Ubiquity\annotations\items\router\GetAnnotation',
36 'getMapping' =>
'Ubiquity\annotations\items\router\GetAnnotation',
37 'post' =>
'Ubiquity\annotations\items\router\PostAnnotation',
38 'postMapping' =>
'Ubiquity\annotations\items\router\PostAnnotation',
39 'put' =>
'Ubiquity\annotations\items\router\PutAnnotation',
40 'putMapping' =>
'Ubiquity\annotations\items\router\PutAnnotation',
41 'patch' =>
'Ubiquity\annotations\items\router\PatchAnnotation',
42 'patchMapping' =>
'Ubiquity\annotations\items\router\PatchAnnotation',
43 'delete' =>
'Ubiquity\annotations\items\router\DeleteAnnotation',
44 'deleteMapping' =>
'Ubiquity\annotations\items\router\DeleteAnnotation',
45 'options' =>
'Ubiquity\annotations\items\router\OptionsAnnotation',
46 'optionsMapping' =>
'Ubiquity\annotations\items\router\OptionsAnnotation',
47 'noRoute' =>
'Ubiquity\annotations\items\router\NoRouteAnnotation',
48 'var' =>
'mindplay\annotations\standard\VarAnnotation',
49 'yuml' =>
'Ubiquity\annotations\items\YumlAnnotation',
50 'rest' =>
'Ubiquity\annotations\items\rest\RestAnnotation',
51 'authorization' =>
'Ubiquity\annotations\items\rest\AuthorizationAnnotation',
52 'injected' =>
'Ubiquity\annotations\items\di\InjectedAnnotation',
53 'autowired' =>
'Ubiquity\annotations\items\di\AutowiredAnnotation'
55 Annotations::$config[
'cache'] =
new AnnotationCache($cacheDirectory .
'/annotations');
60 $annotationManager = Annotations::getManager();
61 foreach ($nameClasses as $name => $class) {
62 self::$registry[$name] = $class;
63 $annotationManager->registry[$name] = $class;
67 protected function register(AnnotationManager $annotationManager) {
68 $annotationManager->registry = \array_merge($annotationManager->registry, self::$registry);
71 public function getAnnotsOfClass(
string $class, ?
string $annotationType =
null): array {
72 return Annotations::ofClass($class, $this->getAnnotationByKey($annotationType));
77 if (\array_key_exists($key, self::$registry)) {
78 return '@' . \ltrim($key,
'@');
84 public function getAnnotsOfProperty(
string $class,
string $property, ?
string $annotationType =
null): array {
85 return Annotations::ofProperty($class, $property, $this->getAnnotationByKey($annotationType));
88 public function getAnnotsOfMethod(
string $class,
string $method, ?
string $annotationType =
null): array {
89 return Annotations::ofMethod($class, $method, $this->getAnnotationByKey($annotationType));
92 public function getAnnotation(?
object $container,
string $key, array $parameters = []): ?object {
93 if (isset(self::$registry[$key])) {
94 $classname = self::$registry[$key];
95 $annot =
new $classname();
96 $annot->initAnnotation($parameters);
103 $annotationsStr =
'';
104 $size = \count($annotations);
106 $annotationsStr = $prefix .
"/**";
107 \array_walk($annotations,
function ($item) {
111 $annotationsStr .=
"\n{$prefix} * " . implode(
"\n{$prefix} * ", $annotations);
113 $annotationsStr .=
"\n{$prefix} * " . \end($annotations);
115 $annotationsStr .=
"\n{$prefix} */";
118 return $annotationsStr;
125 public static function isMany(
object $annotation): bool {
137 public function is(
string $key,
object $annotation): bool {
138 $class = self::$registry[$key] ?? null;
139 if ($class !==
null) {
140 return $annotation instanceof $class;
150 self::registerAnnotations([
151 'allow' => \
Ubiquity\annotations\items\acl\AllowAnnotation::class,
152 'resource' => \
Ubiquity\annotations\items\acl\ResourceAnnotation::class,
153 'permission' => \
Ubiquity\annotations\items\acl\PermissionAnnotation::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")
is(string $key, object $annotation)
static isManyToMany(object $annotation)
getAnnotationByKey(?string $key=null)
getAnnotation(?object $container, string $key, array $parameters=[])
getAnnotsOfProperty(string $class, string $property, ?string $annotationType=null)
register(AnnotationManager $annotationManager)
registerAnnotations(array $nameClasses)
static isManyToOne(object $annotation)
getAnnotsOfMethod(string $class, string $method, ?string $annotationType=null)
Ubiquity\annotations$AnnotationsInterface This class is part of Ubiquity.
Class Configuration \config.