PHPackages                             kutny/autowiring-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. kutny/autowiring-bundle

AbandonedArchivedSymfony-bundle[Framework](/categories/framework)

kutny/autowiring-bundle
=======================

A simple library that provides autowiring for the Symfony Dependency Injection (DI) container.

1.0.2(10y ago)1239.0k3[1 issues](https://github.com/kutny/autowiring-bundle/issues)[1 PRs](https://github.com/kutny/autowiring-bundle/pulls)MITPHPPHP &gt;=5.3.2

Since Feb 24Pushed 10y ago1 watchersCompare

[ Source](https://github.com/kutny/autowiring-bundle)[ Packagist](https://packagist.org/packages/kutny/autowiring-bundle)[ Docs](https://github.com/kutny/autowiring-bundle)[ RSS](/packages/kutny-autowiring-bundle/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (3)DependenciesVersions (4)Used By (0)

Symfony autowiring bundle
=========================

[](#symfony-autowiring-bundle)

A simple library that provides autowiring for the Symfony2 Dependency Injection (DI) container.

This bundle **supports constructor autowiring only**, see  for description.

**Like this Bundle**? Send me your feedback or just "thank you" message to .

Installation
------------

[](#installation)

1. Install via composer:

```
composer require kutny/autowiring-bundle
```

2. Add KutnyAutowiringBundle to your application kernel

```
// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Kutny\AutowiringBundle\KutnyAutowiringBundle(),
        // ...
    );
}
```

Configuration
-------------

[](#configuration)

In most cases this bundle **does not require any configuration**. However if your app fails to start after installing this bundle giving you Kutny\\AutowiringBundle\\Compiler\\CannotResolveParameterException, you may need to remove some services from autowiring. See example bellow:

**Example 1**:

You are receiving Kutny\\AutowiringBundle\\Compiler\\CannotResolveParameterException with message like "Class Thrace\\FormBundle\\Form\\Type\\Select2Type (service **thrace\_form.form.type.select2**), parameter $widget".

The problem is that Thrace\\FormBundle\\Form\\Type\\Select2Type service definition does not contain explicit $widget argument definition. It is very likely that the Thrace\\FormBundle developer just forgot to define the $widget argument. KutnyAutowiringBundle expects all services to have all arguments defined (or have default values). As a result we have to disable autowiring for the thrace\_form.form.type.select2 service by adding it (as a regular expression) among ignored\_services:

```
kutny_autowiring:
    ignored_services: ['thrace_form\.form\.type\.select2']
```

If you run into problems with more services from the Thrace\\FormBundle bundle (thrace\_form.form.type.select2, thrace\_form.form.type.recaptcha, ...), you can easily add the whole "service namespace" to ignored\_services using the following reqular expression:

```
kutny_autowiring:
    ignored_services: ['thrace_form\.form\.type.*']
```

Example 1: Simple controller autowiring
---------------------------------------

[](#example-1-simple-controller-autowiring)

Sample controller with service autowiring (controller itself is also defined as service):

```
namespace Acme\DemoBundle\Controller;

use Acme\DemoBundle\Facade\ProductsFacade;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

/**
 * @Route(service="controller.products_controller")
 */
class ProductsController
{

  private $productsFacade;

    public function __construct(ProductsFacade $productsFacade)
    {
        $this->productsFacade = $productsFacade;
    }

    /**
     * @Route("/", name="route.products")
     * @Template()
     */
    public function productsAction()
    {
        return array(
            'products' => $this->productsFacade->getProducts()
        );
    }

}
```

Services configuration in app/config.yml:

```
services:
    controller.products_controller:
        class: Acme\DemoBundle\Controller\ProductsController

    facade.products_facade:
        class: Acme\DemoBundle\Facade\ProductsFacade
```

Example 2: Partial manual wiring
--------------------------------

[](#example-2-partial-manual-wiring)

In the following example, I've added:

- **$productsPerPageLimit** config option to ProductsController (must be wired manually)
- ProductsRepository manually wired with Doctrine2 EntityManager

```
