PHPackages                             janmarek/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. janmarek/autowiring-bundle

ActiveLibrary[Framework](/categories/framework)

janmarek/autowiring-bundle
==========================

Autowiring bundle for Symfony2

863[1 issues](https://github.com/janmarek/autowiring-bundle/issues)PHP

Since Jul 30Pushed 11y ago3 watchersCompare

[ Source](https://github.com/janmarek/autowiring-bundle)[ Packagist](https://packagist.org/packages/janmarek/autowiring-bundle)[ RSS](/packages/janmarek-autowiring-bundle/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependenciesVersions (2)Used By (0)

Autowiring Bundle [![Build Status](https://camo.githubusercontent.com/e2829cb7ba753997a5c81bee7d50c716cfc2375bad0a892542c8f7cac7daaa12/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6a616e6d6172656b2f6175746f776972696e672d62756e646c652e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/janmarek/autowiring-bundle)
============================================================================================================================================================================================================================================================================================================================================

[](#autowiring-bundle-)

The aim of this Symfony2 bundle is to simplify configuration of services in Symfony Dependency Injection Container.

Autowiring
----------

[](#autowiring)

In Symfony 2 you have to configure parameters of service constructors. But we can use type information to configure service arguments automatically. Autowiring uses PHP reflection to find out how the service constructor parameters look like and what types they have. Then it searches the container for services with classes that can be passed to that argument. If there is only one, autowiring configures that argument automatically for you. Otherwise exception is thrown and you have to configure service manually like you usually do.

Installation instructions
-------------------------

[](#installation-instructions)

Install via composer:

```
composer require janmarek/autowiring-bundle
```

Enable bundle in your application kernel.

```
// app/AppKernel.php
public function registerBundles()
{
    return [
        // ...
        new JanMarek\AutowiringBundle\JanMarekAutowiringBundle(),
        // ...
    ];
}
```

Features
--------

[](#features)

**Constructor autowiring**

```
class Foo
{
    public function __construct(Bar $bar)
    {
        ...
    }
}

class Bar
{

}
```

```
services:
    service_foo:
        class: Foo
        # arguments are configured automatically by types

    service_bar:
        class: Bar
```

**Setter autowiring**

```
class ClassWithSetters
{
    public function setObject(Bar $bar)
    {
        ...
    }
}
```

```
services:
    withSetters:
        class: ClassWithSetters
        calls:
            - [setObject, []] # argument(s) are autowired
```

**Setting arguments by parameter name**

You can set some service constructor or setter arguments by their name in PHP code. Other parameters would be autowired.

```
class ArgsByName
{
    public function __construct(Foo $foo, $namedArg)
    {

    }

    public function setBarAndSomethingElse(Bar $bar, $somethingElse)
    {
        ...
    }
}
```

```
parameters:
    param1: 123
    param2: 456

services:
    service_foo:
        class: Foo

    service_bar:
        class: Bar

    service_with_args_by_name:
        class: ArgsByName
        arguments:
            namedArg: %param1%
            # params foo is autowired
        calls:
            - [setObject, { somethingElse: %param2% }]
            # param bar is autowired
```

**Class guessing by naming convention**

If you don't set service class, AutowiringBundle converts service name to a class name and adds it to service definition if that class exists. Rules for conversion are - underscore names are converted to CamelCase and "." is used as namespace separator.

```
services:
    # class is automatically set to Vendor\NameSpace\ClassName
    vendor.name_space.class_name:
```

**Conflict prevention**

If constructor needs a service and there are more services implementing given interface, autowiring can't normally choose one of them and throws an exception.

But if you name service using naming convention described in previous section, it would be used as a default service in conflict situation.

```
namespace NameSpace;

class Foo
{
    public function __construct(Bar $bar)
    {
        ...
    }
}

class Bar
{
    public function __construct($value)
    {

    }
}
```

```
services:
    name_space.bar:
        class: NameSpace\Bar
        arguments: [123]

    other_bar:
        class: NameSpace\Bar
        arguments: [456]

    name_space.foo:
        class: NameSpace\Foo
        # service name_space.bar is autowired to constructor
```

License
-------

[](#license)

BSD

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 57.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/6de7af31c57b0f760d5e77db6ef76347d8ed8f9e914231554b877d140ced014e?d=identicon)[janmarek](/maintainers/janmarek)

---

Top Contributors

[![janmarek](https://avatars.githubusercontent.com/u/150257?v=4)](https://github.com/janmarek "janmarek (12 commits)")[![pavelkucera](https://avatars.githubusercontent.com/u/332800?v=4)](https://github.com/pavelkucera "pavelkucera (9 commits)")

### Embed Badge

![Health badge](/badges/janmarek-autowiring-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/janmarek-autowiring-bundle/health.svg)](https://phpackages.com/packages/janmarek-autowiring-bundle)
```

###  Alternatives

[laravel/telescope

An elegant debug assistant for the Laravel framework.

5.2k67.8M192](/packages/laravel-telescope)[spiral/roadrunner

RoadRunner: High-performance PHP application server and process manager written in Go and powered with plugins

8.4k12.2M84](/packages/spiral-roadrunner)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M259](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

708181.8M596](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
