PHPackages                             studiow/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. studiow/autowire

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

studiow/autowire
================

Autowire-able container

v0.0.1(9y ago)28[1 issues](https://github.com/studiowbe/autowire/issues)MITPHPPHP &gt;=7.0.0

Since Apr 26Pushed 9y ago2 watchersCompare

[ Source](https://github.com/studiowbe/autowire)[ Packagist](https://packagist.org/packages/studiow/autowire)[ RSS](/packages/studiow-autowire/feed)WikiDiscussions master Synced 4w ago

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

Container Autowire
==================

[](#container-autowire)

This package provides a sort of autowiring wrapper for any psr/container-compatible container.

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

[](#installation)

The (highly) recommended way to install studiow/autowire is by using [Composer](https://getcomposer.org/)

```
composer require studiow/autowire
```

How to use
----------

[](#how-to-use)

In my application, I have a Configuration object. There is also an interface for objects that can use this Configuration.

```
class Configuration
{
    //...
}

interface HasConfiguration
{
    public function setConfiguration(Configuration $configuration);
    public function getConfiguration():Configuration
}
```

I like to use league/container as a DI container, so let's do just that:

```
$container = new League\Container\Container();
$container->share(Configuration::class);
```

Now I would like to make sure that our Configuration object gets passed around to any object that needs it. One way to do this is by defining all classes in the container:

```
class AClassWithConfiguration implements HasConfiguration{
    //...
}

$container->share(AClassWithConfiguration::class, function() use($container){
    $obj = new AClassWithConfiguration();
    $obj->setConfiguration($container->get(Configuration::class));
    return $obj;
});
```

This works great! Unfortunately, we'll need to this for any class that needs the Configuration object. Boring!

Let's see what we can do if we wrap our Container in an autowire container:

```
$container = new League\Container\Container();
$container->share(Configuration::class);

$awContainer = Studiow\Autowire\Container($container);
```

This looks familiar: it's the same DI container as before, but it now gets wrapped into an autowire container.

Here's what we want the autowire container to do: if an object implements the HasConfiguration interface, use the setConfiguration method to pass on the Configuration object

```
$awContainer->attach(HasConfiguration::class, function($item, $awContainer){
   $item->setConfiguration($awContainer->get(Configuration::class));
});
```

The attach method takes 2 arguments: the name of the interface, and a callback. The callback also has 2 arguments: the object we're dealing with, and the autowire container.

The callback will now automatically be executed when resolving objects from the container

```
class AClassWithConfiguration implements HasConfiguration{
    //...
}

$container->share(AClassWithConfiguration::class});

$awContainer = Studiow\Autowire\Container($container);
$obj = $awContainer->get(AClassWithConfiguration::class);

$obj->getConfiguration();
//Configuration object was automatically injected
```

If you want, you can bypass "add classes to container" too:

```
$obj = new AClassWithConfiguration();
$obj = $awContainer->applyCallbacks($obj);
$obj->getConfiguration();
//Configuration object was injected
```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

3353d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0b57a4311f92e06e73f6c646344a069d0088747f22e420a583f91bd3e6ab1729?d=identicon)[studiowbe](/maintainers/studiowbe)

---

Top Contributors

[![willemwollebrants](https://avatars.githubusercontent.com/u/916958?v=4)](https://github.com/willemwollebrants "willemwollebrants (7 commits)")

---

Tags

containerexperimentalphpphp7

### Embed Badge

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

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

###  Alternatives

[symfony/dependency-injection

Allows you to standardize and centralize the way objects are constructed in your application

4.2k455.6M9.3k](/packages/symfony-dependency-injection)[symfony/service-contracts

Generic abstractions related to writing services

2.6k914.7M588](/packages/symfony-service-contracts)[illuminate/contracts

The Illuminate Contracts package.

706130.3M12.9k](/packages/illuminate-contracts)[illuminate/container

The Illuminate Container package.

31182.0M2.3k](/packages/illuminate-container)[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

564576.7k48](/packages/ecotone-ecotone)[symfony/type-info

Extracts PHP types information.

20069.8M263](/packages/symfony-type-info)

PHPackages © 2026

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