Download the PHP package beerline/php-custom-annotations without Composer
On this page you can find all versions of the php package beerline/php-custom-annotations. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download beerline/php-custom-annotations
More information about beerline/php-custom-annotations
Files in beerline/php-custom-annotations
Package php-custom-annotations
Short Description Create and work with custom php annotation with pleasure.
License MIT
Homepage https://github.com/beerline/php-custom-annotations
Informations about the package php-custom-annotations
Php custom annotation
Create and work with custom php annotation with pleasure.
Installation
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable release for this bundle:
$ composer require beerline/php-custom-annotations
Step 2: Enable the Bundle
For Symfony declare new service at config/services.yaml
How to use
To add metadata to property of your class:
- Create metadata class.
- Add annotation
@Annotation
and@Annotation\Target("PROPERTY")
to metadata class. - Annotate property of your class by metadata class.
- Use
Beerline\PhpCustomAnnotations\Metadata\PropertyMetadataPicker::findPropertiesAllMetadata( object $entity )
to get array of all annotation of all property of given class. - Use
Beerline\PhpCustomAnnotations\Metadata\PropertyMetadataPicker::findPropertyCertainMetadata( object $entity, string $metadataClassName )
method to get only properties with specific metadata class.$metadataClassName
is name of metadata class
Examples
Imagine we have Product class.
Some of it’s properties should be translated:
- name
- description
To specify which properties should be translated lets create metadata Class called Translatable
Now mark properies name
and description
by metadata class
That all. All you need now it is use PropertyMetadataPicker
to get this properties
// result
// name: 1
// description: 1