PHPackages                             flashytime/container - 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. flashytime/container

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

flashytime/container
====================

A lightweight PHP dependency injection container.

v1.0.0(7y ago)115MITPHPPHP &gt;=5.6

Since Jul 11Pushed 7y ago1 watchersCompare

[ Source](https://github.com/flashytime/container)[ Packagist](https://packagist.org/packages/flashytime/container)[ RSS](/packages/flashytime-container/feed)WikiDiscussions master Synced 2d ago

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

Container
=========

[](#container)

A lightweight PHP dependency injection container.

### Installation

[](#installation)

```
composer require flashytime/container
```

### Usage

[](#usage)

##### Create a container

[](#create-a-container)

```
use Flashytime\Container\Container;
$container = new Container();
```

##### Register a closure

[](#register-a-closure)

```
$this->container->set('hello', function () {
    return 'Hello World!';
});
echo $this->container->get('hello'); //Hello World!
```

```
$this->container->set('name', function () {
    return 'Mocha';
});
$this->container->set('mocha', function ($container) {
    return sprintf('Hello %s!', $container->get('name'));
});
echo $this->container->get('mocha'); //Hello Mocha!
```

##### Register a instance or class

[](#register-a-instance-or-class)

```
$this->container->set('foo', function () {
    return new Foo();
});
```

or

```
$this->container->set('foo', new Foo());
```

or

```
$this->container->set('foo', 'Flashytime\Container\Tests\Foo');
```

or

```
$this->container->set('foo', Flashytime\Container\Tests\Foo::class);
```

##### Get the entry

[](#get-the-entry)

```
$this->container->get('foo');
```

##### Register a singleton

[](#register-a-singleton)

```
$this->container->setSingleton('foo', Flashytime\Container\Tests\Foo::class);
$first = $this->container->get('foo');
$second = $this->container->get('foo');
var_dump($first === $second); //true
```

##### Dependency Injection

[](#dependency-injection)

```
interface FooInterface
{

}

class Foo implements FooInterface
{
    private $name;
    private $age;

    public function __construct($name = null, $age = 0)
    {
        $this->name = $name;
        $this->age = $age;
    }

    public function setName($name)
    {
        $this->name = $name;
    }

    public function getName()
    {
        return $this->name;
    }

    public function setAge($age)
    {
        $this->age = $age;
    }

    public function getAge()
    {
        return $this->age;
    }
}

class Bar
{
    public $foo;

    public function __construct(FooInterface $foo)
    {
        $this->foo = $foo;
    }

    public function getFoo()
    {
        return $this->foo;
    }
}
```

```
$this->container->set(FooInterface::class, Foo::class);
$this->container->set('bar', Bar::class);
$bar = $this->container->get('bar');
var_dump($bar instanceof Bar); //true
var_dump($bar->getFoo() instanceof Foo); //true
```

see [tests](https://github.com/flashytime/container/blob/master/tests/ContainerTest.php) to get more usages.

### License

[](#license)

[MIT](https://opensource.org/licenses/MIT)

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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

2863d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b97f252d8704b739173de45e442bc69ec205d5e43146e05ddd18efe9893193c6?d=identicon)[flashytime](/maintainers/flashytime)

---

Top Contributors

[![flashytime](https://avatars.githubusercontent.com/u/4725967?v=4)](https://github.com/flashytime "flashytime (1 commits)")

---

Tags

containerdependency-injectiondicontainerdependency-injectiondi

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/flashytime-container/health.svg)

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

###  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)
