PHPackages                             jasny/autowire - 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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. jasny/autowire

AbandonedArchivedLibrary[PSR &amp; Standards](/categories/psr-standards)

jasny/autowire
==============

Autowiring for PSR-11 containers

v1.2.2(6y ago)34.0k↓66.7%11MITPHPPHP &gt;=7.2.0

Since Aug 17Pushed 4y ago1 watchersCompare

[ Source](https://github.com/jasny/autowire)[ Packagist](https://packagist.org/packages/jasny/autowire)[ RSS](/packages/jasny-autowire/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (3)Versions (8)Used By (1)

Autowire for PSR-11 containers
==============================

[](#autowire-for-psr-11-containers)

[![Build Status](https://camo.githubusercontent.com/207eb62b4e656936c46bf29470992868c4b6c8fd7be98114e2ef2146b4119eb6/68747470733a2f2f7472617669732d63692e6f72672f6a61736e792f6175746f776972652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/jasny/autowire)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/4750a507016bfe9bc6342f7a00602c775b5216bd0f03e8c1361185f998cf23ff/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a61736e792f6175746f776972652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jasny/autowire/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/94e6684905171843bde8ff9af41a870a71b9ba03abdf687c16fe1e961ae16e38/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a61736e792f6175746f776972652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jasny/autowire/?branch=master)[![Packagist Stable Version](https://camo.githubusercontent.com/b846693d68902c2021061c99d9f69c0d2d152bd2721b34006c86a27a6a1039db/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a61736e792f6175746f776972652e737667)](https://packagist.org/packages/jasny/autowire)[![Packagist License](https://camo.githubusercontent.com/319f55c1b7fbf92613ba31dfebb278a023582332917f0f80a02b69c7009a2caa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a61736e792f6175746f776972652e737667)](https://packagist.org/packages/jasny/autowire)

Instantiate an object (instead of using `new`), automatically determining the dependencies and getting them from a PSR-11 container.

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

[](#installation)

```
composer require jasny/autowire

```

Usage
-----

[](#usage)

The `ReflectionAutowire` implementation using reflection to determine the type of type constructor parameters.

```
class Foo
{
    public function __construct(ColorInterface $color)
    {
        // ...
    }
}
```

Create a new `Foo` object with autowiring:

```
use Jasny\Autowire\ReflectionAutowire();

$autowire = new ReflectionAutowire($container);

$foo = $autowire->instantiate(Foo::class);
// OR
$foo = $autowire(Foo::class);
```

### Optional parameters

[](#optional-parameters)

If the argument may be `null`, it will be set to `null` if no container entry for the parameter exists.

```
class Foo
{
    public function __construct(?ColorInterface $color)
    {
        // ...
    }
}
```

### Doc comments

[](#doc-comments)

It also parses the [doc comment](http://php.net/reflectionclass.getdoccomment) and can get entry name from `@param`. Entry names must be the first part of the description and surrounded by double quotes.

```
class Bar
{
    /**
     * Class constructor
     *
     * @param string              $color       "config:bar_color"
     * @param ConnectionInterface $connection  "db_connections.default"
     */
    public function __construct(string $color, ConnectionInterface $connection)
    {
        // ...
    }
}
```

*The type from `@param` is not considered. If the type is a single interface (or class), there is little reason not to use type hints in the method parameters. Parsing them is difficult, because it requires converting a class to a fully-qualified-class-name (FQCN), which requires looking at the namespace and `use` statements.*

This library deliberately doesn't support autowiring for properties or methods. Please explicitly call those methods in the container function or use an abstract factory.

### Non-wired parameters

[](#non-wired-parameters)

Additional arguments in `instantiate()` are passed directly to the constructor. No autowiring is applied to these parameters.

```
class Bar
{
    /**
     * Class constructor
     *
     * @param string              $color       A color
     * @param ConnectionInterface $connection  "db_connections.default"
     */
    public function __construct(string $color, ConnectionInterface $connection)
    {
        // ...
    }
}
```

```
use Jasny\Autowire\ReflectionAutowire();

$autowire = new ReflectionAutowire($container);

$foo = $autowire->instantiate(Foo::class, 'blue');
```

*The constructor MUST begin with these parameters. It's not possible to cherry-pick the parameters than need to be autowired.*

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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.

###  Release Activity

Cadence

Every ~101 days

Recently: every ~134 days

Total

7

Last Release

2212d ago

PHP version history (2 changes)v1.0.0PHP &gt;=7.1.0

v1.2.1PHP &gt;=7.2.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/3379a93d51305df325df9045e1a8b205d195e4e8c01312dff53a000ee79002eb?d=identicon)[jasny](/maintainers/jasny)

---

Top Contributors

[![jasny](https://avatars.githubusercontent.com/u/100821?v=4)](https://github.com/jasny "jasny (16 commits)")

---

Tags

autowirecontainersphp7psr-11

### Embed Badge

![Health badge](/badges/jasny-autowire/health.svg)

```
[![Health](https://phpackages.com/badges/jasny-autowire/health.svg)](https://phpackages.com/packages/jasny-autowire)
```

###  Alternatives

[pimple/pimple

Pimple, a simple Dependency Injection Container

2.7k130.5M1.4k](/packages/pimple-pimple)[league/container

A fast and intuitive dependency injection container.

86387.8M342](/packages/league-container)[lctrs/psalm-psr-container-plugin

Let Psalm understand better psr11 containers

17648.1k13](/packages/lctrs-psalm-psr-container-plugin)[phpwatch/simple-container

A fast and minimal PSR-11 compatible Dependency Injection Container with array-syntax and without auto-wiring

1810.1k2](/packages/phpwatch-simple-container)

PHPackages © 2026

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