rfc:annotations_v2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
rfc:annotations_v2 [2019/02/05 22:59]
brzuchal Distinguished between Meta-Annotations and Built-in Annotations
rfc:annotations_v2 [2019/08/26 06:48] (current)
brzuchal
Line 21: Line 21:
  
 <code php> <code php>
-@AnnotationName("​value", ​namedParamter=true, embeded=@EmbededAnnotation)+[@AnnotationName("​value",​ true)
 +[SimpleAnnotation] 
 +class Foo {}
 </​code>​ </​code>​
  
Line 34: Line 36:
 use ORM\Column; use ORM\Column;
  
-@Entity +[@Entity] 
-@Table("​foo"​)+[@Table("​foo"​)]
 class Foo { class Foo {
-    @Id @Column("​id", ​type="​uuid"​)+    ​[@Id
 +    [@Column("​id",​ "​uuid"​)]
     private $id;     private $id;
 } }
Line 46: Line 49:
  
 class FooController { class FooController {
-    @Route("/​api/​foo", ​methods=["​POST"​], ​name="​foo_create"​)+    ​[@Route("/​api/​foo",​ ["​POST"​],​ "​foo_create"​)]
     public function create(Request $request): Response     public function create(Request $request): Response
     {     {
Line 58: Line 61:
 First, there are several that inform compilation:​ First, there are several that inform compilation:​
  
-=== @Compiled ===+=== [Compiled===
 Function scoped annotation indicating if a function should be JIT compiled. Function scoped annotation indicating if a function should be JIT compiled.
  
-=== @SupressWarnings ===+=== [SupressWarnings===
 Function or statement scoped annotation indicating if error supression should be applied. Function or statement scoped annotation indicating if error supression should be applied.
  
Line 70: Line 73:
 For example, these meta-annotations are used for annotation configuration:​ For example, these meta-annotations are used for annotation configuration:​
  
-=== @Annotation ===+=== [@Annotation===
 Annotation classes have to contain a ''​@Annotation''​. Annotation classes have to contain a ''​@Annotation''​.
  
 <code php> <code php>
-@Annotation+[@Annotation]
 class MyAnnotation { class MyAnnotation {
     // some code     // some code
Line 80: Line 83:
 </​code>​ </​code>​
  
-=== @Target ===+=== [@Target===
 ''​@Target''​ annotation indicates the kinds of the class element or a function which an annotation type is applicable. ''​@Target''​ annotation indicates the kinds of the class element or a function which an annotation type is applicable.
 Then you could define one or more targets: Then you could define one or more targets:
Line 91: Line 94:
   * ''​ANNOTATION''​ allowed before annotation class declaration   * ''​ANNOTATION''​ allowed before annotation class declaration
  
-=== @Repeatable ===+=== [@Repeatable===
 ''​@Repeatable''​ annotation indicates the annotation may be repeated multiple times when annotating. ''​@Repeatable''​ annotation indicates the annotation may be repeated multiple times when annotating.
  
-=== @Inherited ===+=== [@Inherited===
 ''​@Inherited''​ annotation can be used as meta-annotation on the other user-defined annotation classes. ​ ''​@Inherited''​ annotation can be used as meta-annotation on the other user-defined annotation classes. ​
 When such user-defined annotations are used on superclass, they are automatically inherited to subclasses. When such user-defined annotations are used on superclass, they are automatically inherited to subclasses.
  
 <code php> <code php>
-@Annotation+[@Annotation]
 class MyAnnotation {} class MyAnnotation {}
  
-@Annotation +[@Annotation] 
-@Inherited+[@Inherited]
 class MyInheritedAnnotation {} class MyInheritedAnnotation {}
  
-@MyAnnotation +[@MyAnnotation] 
-@MyInheritedAnnotation+[@MyInheritedAnnotation]
 class Foo {} class Foo {}
  
Line 127: Line 130:
 namespace Example; namespace Example;
  
-@Annotation +[@Annotation] 
-@Target("​class"​)+[@Target("​class"​)]
 class MyAnnotation { class MyAnnotation {
-    @Required+    ​[@Required]
     public string $myProperty;​     public string $myProperty;​
     public array $myArrayProperty = [];     public array $myArrayProperty = [];
Line 136: Line 139:
 } }
  
-@Annotation +[@Annotation] 
-@Target(["​class",​ "​annotation"​])+[@Target(["​class",​ "​annotation"​])]
 class MyEmbededAnnotation { class MyEmbededAnnotation {
 } }
  
-@Annotation +[@Annotation] 
-@Target("​property"​)+[@Target("​property"​)]
 class MyPropertyAnnotation { class MyPropertyAnnotation {
 } }
Line 162: Line 165:
 use Example\MyEmbededAnnotation;​ use Example\MyEmbededAnnotation;​
  
-@MyAnnotation( +[@MyAnnotation([ 
-    myProperty="​value",​  +    ​"myProperty" ​="​value",​  
-    myArrayProperty=[1,​ 3.14, true, "​string",​ DIRECTORY_SEPARATOR], ​ +    ​"myArrayProperty" ​[1, 3.14, true, "​string",​ DIRECTORY_SEPARATOR],​  
-    myEmbeded=@MyEmbededAnnotation() +)]
-)+
 class Foo { class Foo {
-    @MyPropertyAnnotation+    ​[@MyPropertyAnnotation]
     private $property;     private $property;
   ​   ​
-    @MyMethodAnnotation("​value"​)+    ​[@MyMethodAnnotation("​value"​)]
     public function bar() {}     public function bar() {}
 } }
rfc/annotations_v2.1549407555.txt.gz · Last modified: 2019/02/05 22:59 by brzuchal