-
Notifications
You must be signed in to change notification settings - Fork 12
Annotation
The annotation library allows parsing of "annotation" like statements out of docblocks. Yes, there are others out there, but this is the only one I know of under a permissive license... well it was, until Doctrine moved to the MIT license two weeks ago, anyway.
Annotation names are expected to resolve to PHP classes which have been annotated with the @\Weasel\Annotation\Config\Annotations\Annotation
annotation. The resolution of names will make use of any namespace aliasing.
You can parse annotations using the combination of an AnnotationReader and an AnnotationConfigurator. The AnnotationReader providers an interface that allows you to read back the annotation objects for a given class. The Configurator provides the configuration for annotations.
To be valid an annotation must appear at the start of a line of docblock (the * is required too.) The arguments list can be split over multiple lines, and * appearing at the start of a new line will be ignored.
At present the only implementation of AnnotationConfigurator knows about a small number of "built in" annotations, and then expects to be able to use those to configure any further annotations it runs into.
The annotation library has a simple type system, which it shares with other Weasel libraries. Documentation can be found: AnnotationTypes
Namespace: \Weasel\Annotation\Config\Annotations
- @Annotation Marks a class as being an annotation
- @AnnotationCreator Allows constructor args or a factory method for creating an annotation object
- @Enum Marks a property as being an enum
- @Parameter Configuration for parameters of an @AnnotationCreator
- @Property A property to be set from the parameters to the annotation
(using w3c XML style EBNFish)
DocAnnotation ::= Preamble Annotation B;
Annotation ::= "@" ClassName ("(" Parameters ")")?;
Parameters ::= B* Parameter B* ("," B* Parameter B*)*;
Parameter ::= (QuotedString | Integer | Bool | Float | Annotation | Array);
QuotedString ::= "\"" (NotQuotes | "\"\"")* "\"";
Integer ::= ("+" | "-")? Digits+;
Float ::= ("+" | "-")? Digits+ ( "." Digits+ )? ( ( "e" | "E" ) ( "+" | "-" ) Digits+)?;
Array ::= "{" Parameters "}";
ClassName ::= '\'? Identifier ("\", Identifier)*;
Identifier ::= [a-zA-Z_\x7f-\xff] [a-zA-Z0-9_\x7f-\xff]*;
Preamble ::= V+ S+ "*" S+;
B ::= S | V | Preamble
S ::= ? white space characters ?
V ::= ? vertical space characters ?;
NotQuotes ::= AllCharacters - "\"";
AllCharacters ::= ? all visible characters ? ;
Digits ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;