symplify/default-autowire

This package is abandoned and no longer maintained. The author suggests using the symfony/dependency-injection package instead.
There is no license information available for the latest version (v2.0.0-RC2) of this package.

Adds autowire to services when needed.

v2.0.0-RC2 2017-04-27 14:57 UTC

README

Build Status Code Coverage Downloads

This bundle turns on autowire for you!

It turns this:

# app/config/config.yml
services:
    PriceCalculator:
        autowire: true

    ProductRepository:
        autowire: true

    UserFactory:
        autowire: true

Into this:

# app/config/config.yml
services:
    PriceCalculator: ~
    ProductRepository: ~
    UserFactory: ~

Install

composer require symplify/default-autowire

Add bundle to AppKernel.php:

final class AppKernel extends Kernel
{
    public function registerBundles(): array
    {
        $bundles = [
            new Symplify\DefaultAutowire\SymplifyDefaultAutowireBundle(),
            // ...
        ];
    }
}

And that's it!

Features

Multiple service of one type? Set preferred one

In case you have multiple connections, entity managers or decorated service, you can set default preferred service (name) for each type (class or interface).

To make it easier for you, there are few default values. You can change them or add new ones.

# app/config/cofing.yml
symplify_default_autowire:
    autowire_types:
        Doctrine\ORM\EntityManager: 'doctrine.orm.default_entity_manager'
        Doctrine\ORM\EntityManagerInterface: 'doctrine.orm.default_entity_manager'
        Doctrine\Portability\Connection: 'database_connection'
        Symfony\Component\EventDispatcher\EventDispatcher: 'event_dispatcher'
        Symfony\Component\EventDispatcher\EventDispatcherInterface: 'event_dispatcher'
        Symfony\Component\Translation\TranslatorInterface: 'translator'

Contributing

Send issue or pull-request to main repository.