rfc:annotations_v2
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:annotations_v2 [2019/02/05 22:59] – Distinguished between Meta-Annotations and Built-in Annotations brzuchal | rfc:annotations_v2 [2020/07/22 08:44] (current) – brzuchal | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2019-02-05 | * Date: 2019-02-05 | ||
* Author: Michał Brzuchalski < | * Author: Michał Brzuchalski < | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 21: | Line 21: | ||
<code php> | <code php> | ||
- | @AnnotationName(" | + | [@AnnotationName(" |
+ | [SimpleAnnotation] | ||
+ | class Foo {} | ||
</ | </ | ||
Line 34: | Line 36: | ||
use ORM\Column; | use ORM\Column; | ||
- | @Entity | + | [@Entity] |
- | @Table(" | + | [@Table(" |
class Foo { | class Foo { | ||
- | @Id @Column(" | + | |
+ | [@Column(" | ||
private $id; | private $id; | ||
} | } | ||
Line 46: | Line 49: | ||
class FooController { | class FooController { | ||
- | @Route("/ | + | |
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 classes have to contain a '' | ||
<code php> | <code php> | ||
- | @Annotation | + | [@Annotation] |
class MyAnnotation { | class MyAnnotation { | ||
// some code | // some code | ||
Line 80: | Line 83: | ||
</ | </ | ||
- | === @Target === | + | === [@Target] === |
'' | '' | ||
Then you could define one or more targets: | Then you could define one or more targets: | ||
Line 91: | Line 94: | ||
* '' | * '' | ||
- | === @Repeatable === | + | === [@Repeatable] === |
'' | '' | ||
- | === @Inherited === | + | === [@Inherited] === |
'' | '' | ||
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(" | + | [@Target(" |
class MyAnnotation { | class MyAnnotation { | ||
- | @Required | + | |
public string $myProperty; | public string $myProperty; | ||
public array $myArrayProperty = []; | public array $myArrayProperty = []; | ||
Line 136: | Line 139: | ||
} | } | ||
- | @Annotation | + | [@Annotation] |
- | @Target([" | + | [@Target([" |
class MyEmbededAnnotation { | class MyEmbededAnnotation { | ||
} | } | ||
- | @Annotation | + | [@Annotation] |
- | @Target(" | + | [@Target(" |
class MyPropertyAnnotation { | class MyPropertyAnnotation { | ||
} | } | ||
Line 162: | Line 165: | ||
use Example\MyEmbededAnnotation; | use Example\MyEmbededAnnotation; | ||
- | @MyAnnotation( | + | [@MyAnnotation([ |
- | myProperty=" | + | |
- | myArrayProperty=[1, | + | |
- | myEmbeded=@MyEmbededAnnotation() | + | )] |
- | ) | + | |
class Foo { | class Foo { | ||
- | @MyPropertyAnnotation | + | |
private $property; | private $property; | ||
| | ||
- | @MyMethodAnnotation(" | + | |
public function bar() {} | public function bar() {} | ||
} | } |
rfc/annotations_v2.txt · Last modified: 2020/07/22 08:44 by brzuchal