Download the PHP package egorov/yii2-annotations without Composer
On this page you can find all versions of the php package egorov/yii2-annotations. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download egorov/yii2-annotations
More information about egorov/yii2-annotations
Files in egorov/yii2-annotations
Package yii2-annotations
Short Description Allows you to use doctrine/annotations in Yii2 projects
License MIT
Informations about the package yii2-annotations
Yii2 Annotations extension
Use doctrine/annotations in Yii2 projects with Yii2 caching drivers
Install
**Configuration**
where :
class - yii\annotations\Annotations class or class implementing yii\annotations\AnnotationsInterface,
cache - Optional. Container with cache component defined in configuration or cache class. By default 'cache',
path - Optional. Annotations cache dir for \yii\caching\FileCache,
debug - Optional boolean. Debug enable. True means that the cache will be invalid every time the file is changed, false - the cache will be generated once
ignoreAnnotations - List of ignored annotations when parsing a file
Annotation class
Annotation classes have to contain a class-level docblock with the text @Annotation: `
Inject annotation values
The annotation parser check if the annotation constructor has arguments, if so then we will pass the value array, otherwise will try to inject values into public properties directly: `
Annotation Target
@Target indicates the kinds of class element to which an annotation type is applicable. Then you could define one or more targets:
CLASS Allowed in the class docblock PROPERTY Allowed in the property docblock METHOD Allowed in the method docblock ALL Allowed in the class, property and method docblock ANNOTATION Allowed inside other annotations If the annotations is not allowed in the current context you got an AnnotationException `
Attribute types
Annotation parser check the given parameters using the phpdoc annotation @var, The data type could be validated using the @var annotation on the annotation properties or using the annotations @Attributes and @Attribute.
If the data type not match you got an AnnotationException ` Annotation Required
@Required indicates that the field must be specified when the annotation is used. If it is not used you get an AnnotationException stating that this value can not be null.
Declaring a required field:
Usage:
Enumerated values
An annotation property marked with @Enum is a field that accept a fixed set of scalar values. You should use @Enum fields any time you need to represent fixed values. The annotation parser check the given value and throws an AnnotationException if the value not match. Declaring an enumerated property:
Annotation usage:
Constants
The use of constants and class constants are available on the annotations parser.
The following usage are allowed: ` Be careful with constants and the cache !
The cached reader will not re-evaluate each time an annotation is loaded from cache. When a constant is changed the cache must be cleaned.
Usage Example
Create annotations class
Write annotations in target class
Reader API
Access all annotations of a class `
Access one annotation of a class `
Access all annotations of a method `
Access one annotation of a method `
Access all annotations of a property `
Access one annotation of a property `
Get parser
Parse annotation directly from docBlock. Its not cached



