Download the PHP package simonmarx/symfony-service-annotations without Composer
On this page you can find all versions of the php package simonmarx/symfony-service-annotations. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package symfony-service-annotations
Installation
Enable the Bundle (when not using Symfony flex)
Enable the bundle by adding it to the list of registered bundles
in the config/bundles.php
file of your project:
Usage
When using Symfonys autowire feature, some stuff like service aliases or service tags must be configured in the services.yaml/xml file.
This bundle tries to prevent the developer from having to enter the services.yaml and configure services there in the class itselfs.
It makes service classes feels more like a standalone service since the class holds all service configuration itself.
Important
Bundle and readme is currently under construction but should work anyways.
- [ ] Write better documentation
- [ ] Add tests
- [ ] Add decoration support
Examples
Example 1: Tagged services with an interfaces
When annotate an interface or abstract class with @ServiceTag
all extending classes which implements the interface or
extends the abstract class will be registered as a tagged service.
When you want to tag a single class instead an interface or abstract class, simply use the annotation the same way as in this example.
Example 2: Service tag attributes definition
When using the interface/abstract service tagging (see Example 1) you can overwrite tag arguments in your child class
by using @ServiceTagArgument
.
You also can use this annotation in a normal class to add arguments to any tag
When you define more than 1 annotation of type @ServiceTag
in your class or your parent class/interface you must
specify for which tag your annotation @ServiceTagArgument
is responsible.
e.g. @ServiceTagArgument(tag="my_tag", argument="priority", value=-23)
Example 3: Service Alias
By using the annotation @ServiceAlias
you can specify an alias for you service class.
Example 4: Prevent loading classes as service (e.g. when using autowire)
Sometimes you dont want that your class is loaded into die dic, for that you can use the @NoService
annotation.
Every class which is annotated with this annotation would be removed from the symfony container before container build is finished.
Example 5: Ignore annotation from parent classes
In default annotation from parent classes (as long as they are abstract or interfaces) will be used for your child class to.
To prevent unwanted service configurations you can use the @IgnoreParentServiceAnnotations
annotation.
Example 6: DependencyInjection via Annotation
In case you want to inject something from your container into the constructor (e.g. tagged_iterator) which is not handled by autowiring
you can use the @DependencyInjection
annotation.
Example 7: Assign Parent service
If your current service requires a parent service, just annotate your service class with @ParentService
, the compilerpass
will redefine your service as a ChildDefinition and replace it in the service container
All versions of symfony-service-annotations with dependencies
symfony/framework-bundle Version >=3.0
doctrine/annotations Version ^1.10