PHPackages                             chiron/injector - 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. chiron/injector

ActiveLibrary

chiron/injector
===============

Give it a nice description!

0.2.6(4y ago)14.9k2MITPHPPHP ^8.0 || ^8.1

Since Jun 1Pushed 3y ago1 watchersCompare

[ Source](https://github.com/ncou/injector)[ Packagist](https://packagist.org/packages/chiron/injector)[ GitHub Sponsors](https://github.com/ncou)[ RSS](/packages/chiron-injector/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (8)Dependencies (2)Versions (9)Used By (2)

Chiron Injector
===============

[](#chiron-injector)

[![Build Status](https://github.com/ncou/injector/workflows/build/badge.svg)](https://github.com/ncou/injector/actions)[![Static Analysis](https://github.com/ncou/injector/workflows/static%20analysis/badge.svg)](https://github.com/ncou/injector/actions?query=workflow%3A%22static+analysis%22)

[![CodeCov](https://camo.githubusercontent.com/709bbeb38083b96909db37bce6fc4279c3dc757eb900aa9a50ab2a066da44e37/68747470733a2f2f636f6465636f762e696f2f67682f6e636f752f696e6a6563746f722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/ncou/injector)

[![Latest Stable Version](https://camo.githubusercontent.com/a1d7a152fb561cfa3e5bd2057965a44678535b77fdc48cf1297b0a325520a36f/68747470733a2f2f706f7365722e707567782e6f72672f636869726f6e2f696e6a6563746f722f762f737461626c652e706e67)](https://packagist.org/packages/chiron/injector)[![Total Downloads](https://camo.githubusercontent.com/874ef88da4d596aa60ed89fe30de298a6a62a1dcd56614a784ea46f321b56e90/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636869726f6e2f696e6a6563746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chiron/injector/stats)[![Monthly Downloads](https://camo.githubusercontent.com/34e50b79fe9ccbcbff883b2567dd180eb773962177169fe54bb44902f41f5ea3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f636869726f6e2f696e6a6563746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chiron/injector/stats)[![Total Downloads](https://camo.githubusercontent.com/874ef88da4d596aa60ed89fe30de298a6a62a1dcd56614a784ea46f321b56e90/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636869726f6e2f696e6a6563746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chiron/injector)

[![Latest Version](https://camo.githubusercontent.com/6b7e3f7159022b0b934e9acd197b0b5194bbaf1dc39f1b0a685275c6607fdb71/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f6e636f752f696e6a6563746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chiron/injector)[![Total Downloads](https://camo.githubusercontent.com/874ef88da4d596aa60ed89fe30de298a6a62a1dcd56614a784ea46f321b56e90/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636869726f6e2f696e6a6563746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chiron/injector)

A [dependency injection](http://en.wikipedia.org/wiki/Dependency_injection)implementation based on autowiring and [PSR-11](http://www.php-fig.org/psr/psr-11/) compatible dependency injection containers.

#### Features

[](#features)

- Injects dependencies when calling functions and creating objects
- Works with any dependency injection container (DIC) that is [PSR-11](http://www.php-fig.org/psr/psr-11/) compatible
- Accepts additional dependencies and arguments passed as array
- Allows passing arguments *by parameter name* in the array
- Resolves object type dependencies from the container and the passed array by [parameter type declaration](https://www.php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration)
- Resolves [variadic arguments](https://www.php.net/manual/en/functions.arguments.php#functions.variable-arg-list)i.e. `function (MyClass ...$a)`

Requirements
------------

[](#requirements)

- PHP 7.4 or higher.

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

[](#installation)

The package could be installed with composer:

```
composer require chiron/injector
```

About
-----

[](#about)

Injector can automatically resolve and inject dependencies when calling functions and creating objects.

It therefore uses [Reflection](https://www.php.net/manual/en/book.reflection.php) to analyze the parameters of the function to call, or the constructor of the class to instantiate and then tries to resolve all arguments by several strategies.

The main purpose is to find dependency objects - that is arguments of type object that are declared with a classname or an interface - in a (mandatory) [PSR-11](http://www.php-fig.org/psr/psr-11/) compatible *dependency injection container* (DIC). The container must therefore use the class or interface name as ID.

In addition, an array with arguments can be passed that will also be scanned for matching dependencies. To make things really flexible (and not limited to objects), arguments in that array can optionally use a function parameter name as key. This way basically any callable can be invoked and any object be instantiated by the Injector even if it uses a mix of object dependencies and arguments of other types.

Basic Example
-------------

[](#basic-example)

```
// A function to call
$fn = function (Foo $a, Bar $b, int $c) { /* ... */ };

// Arbitrary PSR-11 compatible object container
$container = new \some\di\Container([
    Foo::class => new Foo(), // will be used as $a
]);

// Prepare the injector
$injector = new Injector($container);

// Use the injector to call the function and resolve dependencies
$result = $injector->invoke($fn, [
    'c' => 15,  // will be used as $c
    new Bar(),  // will be used as $b
]);
```

Documentation
-------------

[](#documentation)

Documentation can be found [here](docs/README.md).

Testing
-------

[](#testing)

### Unit testing

[](#unit-testing)

The package is tested with [PHPUnit](https://phpunit.de/). To run tests:

```
composer phpunit
```

### Static analysis

[](#static-analysis)

The code is statically analyzed with [Phpstan](https://phpstan.org/). To run static analysis:

```
composer phpstan
```

### Coding standard

[](#coding-standard)

The code should follow the [Chiron Coding Standard](https://github.com/ncou/coding-standard). To apply coding standard:

```
# detect violations of the defined coding standard.
composer check-style
```

```
# automatically correct coding standard violations.
composer fix-style
```

License
-------

[](#license)

The Chiron Injector is free software. It is released under the terms of the MIT License. Please see [`LICENSE`](./LICENSE.md) for more information.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity60

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 ~84 days

Recently: every ~119 days

Total

8

Last Release

1582d ago

PHP version history (3 changes)0.1PHP ^7.2

0.2.5PHP ^8.0|^8.1

0.2.6PHP ^8.0 || ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16743322?v=4)[ncou](/maintainers/ncou)[@ncou](https://github.com/ncou)

---

Top Contributors

[![ncou](https://avatars.githubusercontent.com/u/16743322?v=4)](https://github.com/ncou "ncou (56 commits)")

### Embed Badge

![Health badge](/badges/chiron-injector/health.svg)

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

###  Alternatives

[pimple/pimple

Pimple, a simple Dependency Injection Container

2.7k130.5M1.4k](/packages/pimple-pimple)[neos/flow

Flow Application Framework

862.0M451](/packages/neos-flow)[api-platform/state

API Platform state interfaces

223.4M57](/packages/api-platform-state)[internal/dload

Downloads binaries.

98142.7k10](/packages/internal-dload)[symfony/json-streamer

Provides powerful methods to read/write data structures from/into JSON streams.

14440.0k8](/packages/symfony-json-streamer)[rubix/server

Deploy your Rubix ML models to production with scalable stand-alone inference servers.

632.3k](/packages/rubix-server)

PHPackages © 2026

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