PHPackages                             parable-php/di - 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. parable-php/di

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

parable-php/di
==============

Parable DI is a micro Dependency Injection Container

1.0.1(1y ago)589724MITPHPPHP &gt;=8.0

Since Aug 9Pushed 1y ago1 watchersCompare

[ Source](https://github.com/parable-php/di)[ Packagist](https://packagist.org/packages/parable-php/di)[ Docs](https://github.com/parable-php/di)[ RSS](/packages/parable-php-di/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (17)Used By (4)

Parable DI Container
====================

[](#parable-di-container)

[![Workflow Status](https://github.com/parable-php/di/workflows/Tests/badge.svg)](https://github.com/parable-php/di/actions?query=workflow%3ATests)[![Latest Stable Version](https://camo.githubusercontent.com/1b367eb48c66e20e2b1b1903f3a96835d32fd94c72d27e3d1c50466c58ce80b5/68747470733a2f2f706f7365722e707567782e6f72672f70617261626c652d7068702f64692f762f737461626c65)](https://packagist.org/packages/parable-php/di)[![Latest Unstable Version](https://camo.githubusercontent.com/0fac053357c875b4846711931ea3586ab8cb08fbb4cd31e7fa95e6802aac8098/68747470733a2f2f706f7365722e707567782e6f72672f70617261626c652d7068702f64692f762f756e737461626c65)](https://packagist.org/packages/parable-php/di)[![License](https://camo.githubusercontent.com/6b4ac823d5d3e94a55465477cd01365cafde6368fcae434d08b94f6cc6866e8e/68747470733a2f2f706f7365722e707567782e6f72672f70617261626c652d7068702f64692f6c6963656e7365)](https://packagist.org/packages/parable-php/di)

Parable DI is a no-nonsense dependency injection container that gets the job done.

Install
-------

[](#install)

Php 8.0+ and [composer](https://getcomposer.org) are required.

```
$ composer require parable-php/di
```

Usage
-----

[](#usage)

Example usage of a straightforward situation:

```
use \Parable\Di\Container;

$container = new Container();

$app = $container->get(App::class);
$app->run();
```

Example usage of an interface-hinted dependency being mapped:

```
use \Parable\Di\Container;

$container = new Container();

class App
{
    public function __construct(ThatInterface $classWithThatInterface)
    {
    }

    public function run()
    {
        echo "Run? RUN!";
    }
}

$container->map(ThatInterface::class, ClassWithThatInterface::class);

$app = $container->get(App::class);
$app->run();
```

The above situation can also be solved by instantiating and then storing `ClassWithThatInterface` under `ThatInterface`.

Example usage of a class that needs the di itself, in case you need to do dynamic DI:

```
use \Parable\Di\Container;

$container = new Container();

class App
{
    public $container;
    public function __construct(
        public Container $container
    ) {}
}

$app = $container->get(App::class);
var_dump($app->container->has(App::class)); // output: bool(true)
```

For all other use cases, simply check the tests in `tests/ContainerTest.php`.

API
---

[](#api)

- `get(string $name): object` - creates or gets instance
- `has(string $name): bool` - check if instance is stored
- `assertHas(string $name): void` - check and throw exception if instance is not stored
- `build(string $name): object` - build instance with stored deps, don't store
- `buildAll(string $name): object` - build instance with new deps, don't store
- `map(string $requested, string $replacement): void` - allow pre-emptively defining a replacement class to be instantiated when the requested name is retrieved or built. Use for lazy-loading classes, i.e. for interface deps.
- `unmap(string $requested): void` - removes the mapping *and* clears any previously mapped instances
- `getDependenciesFor(string $name, [int $storedDependencies]): array` - get dependencies for instance, with stored (default) or new deps
- `store(object $instance, [string $name]): void` - store instance under name, or under instance name by default
- `clear(string $name): void` - clear instance
- `clearExcept(array $keep): void` - clear all except provided names, throws if any of the instances to keep doesn't exist
- `clearAll(): void` - clear all

Where `object` refers to any instance of any class.

Contributing
------------

[](#contributing)

Any suggestions, bug reports or general feedback is welcome. Use github issues and pull requests, or find me over at [devvoh.com](https://devvoh.com).

License
-------

[](#license)

All Parable components are open-source software, licensed under the MIT license.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance42

Moderate activity, may be stable

Popularity23

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 66.7% 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 ~157 days

Recently: every ~368 days

Total

16

Last Release

472d ago

Major Versions

0.3.2 → 1.0.02021-03-12

PHP version history (2 changes)0.1.0PHP &gt;=7.1

0.3.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/7db40df70c77a9d591de4521642b0ddcb6c448e4876b22dc2f76900c736ab579?d=identicon)[robindevoh](/maintainers/robindevoh)

---

Top Contributors

[![dmvdbrugge](https://avatars.githubusercontent.com/u/14186025?v=4)](https://github.com/dmvdbrugge "dmvdbrugge (2 commits)")[![devvoh](https://avatars.githubusercontent.com/u/7500415?v=4)](https://github.com/devvoh "devvoh (1 commits)")

---

Tags

dependencydependency-injectiondepsdiparableparable-diphp8service-containercontainerdependency-injectionmicrolibrarydiparable

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/parable-php-di/health.svg)

```
[![Health](https://phpackages.com/badges/parable-php-di/health.svg)](https://phpackages.com/packages/parable-php-di)
```

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.8k48.9M994](/packages/php-di-php-di)[aura/di

A serializable dependency injection container with constructor and setter injection, interface and trait awareness, configuration inheritance, and much more.

356968.3k58](/packages/aura-di)[mrclay/props-dic

Props is a simple DI container that allows retrieving values via custom property and method names

3611.7M3](/packages/mrclay-props-dic)[slince/di

A flexible dependency injection container

20260.4k6](/packages/slince-di)[capsule/di

A PSR-11 compliant autowiring dependency injection container.

2857.5k2](/packages/capsule-di)

PHPackages © 2026

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