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

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

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

Give it a nice description!

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

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 3w 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

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

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

1631d 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

[symfony/dependency-injection

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

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

The Illuminate Contracts package.

706130.3M13.4k](/packages/illuminate-contracts)[illuminate/container

The Illuminate Container package.

31182.0M2.4k](/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.7k53](/packages/ecotone-ecotone)[symfony/type-info

Extracts PHP types information.

20069.8M270](/packages/symfony-type-info)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)

PHPackages © 2026

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