Download the PHP package hco/auto-wiring-bundle without Composer
On this page you can find all versions of the php package hco/auto-wiring-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package auto-wiring-bundle
HCO Auto Wiring Bundle
This bundle eases the usage of the symfony2 DIC by injecting (constructor) dependencies automatically.
All classes that should be autowired have to have a specific tag within the DIC. The Bundle will then iterate over the constructor-parameters and will try to find a service that satisfies the typehint of every parameter.
If there is not exactly one service that satisfies the typehint, the autowiring will fail. Qualifiers and Primary Services might help you to solve that issue, though :)
The autowiring process is done during compile time of the service container, which means that it should not have any performance impact in production.
Stability
I already use this bundle in an application, and it's working quite well. I am not yet releasing a 1.0 though, as I'm looking forward to feedback and experiences.
I intend to keep every change backwards compatible.
Qualifiers
A service can have a so called "qualifier", which will allow autowiring of typehints which could be satisfied by several services.
An example could be your database connection. Imagine, you have two database connections within your service container, one for write requests and one for readonly requests. You could now give both services a qualifier, "write" for the write-database connection and "readonly" for the readonly database connection.
If a service now has an unqualified typehint for a database connection, the autowiring will fail. But you can now qualify a typehint with the string we used before, so that a service will be wired to one specific database connection.
Primary Services
A service an be tagged to be a so called primary service. When a dependency should be outwired, and there is exactly one primary service, that will be outwired. There can still be several non-primary services for a class, but they will be ignored.
If two services are declared to be primary which are of the same type, the compilation of the container will fail.
Example
Imagine you define the following class with the following service configuration
This will automatically inject the service bar into the service foo.
Example with qualifiers
We're gonna reuse the ServiceWithDependency class from above, but modify the service configuration.
That will fail, as the autowiring bundle does not know which service should be injected anymore. This is where qualifiers come into play. We can slightly modify the class and service definition.
This will injcet the service baz into the service foobar, as baz is qualified as readonly.
Qualifiers can also be configured within the XML:
Something similar will work with YAML, as i just use tags on services.
Example with Primary
If we tag the service baz as primary, it will be used as the StdClass dependency of our ServiceWithDependency. See the following services.xml as an example.
License
This bundle is under the MIT license. See the complete license in the LICENSE file in the root of this repository.
All versions of auto-wiring-bundle with dependencies
symfony/dependency-injection Version ~2.3
symfony/config Version ~2.3