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

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

hypario/container
=================

A simple container i tried to make like PHP-DI

1.1.0(5y ago)049MITPHPPHP ^8.0

Since Sep 8Pushed 5y agoCompare

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

READMEChangelogDependenciesVersions (11)Used By (0)

[![Build Status](https://camo.githubusercontent.com/452494f134964d2f5a4e365041a086f9baa5f381dd81ae569b8965a4405839c9/68747470733a2f2f7472617669732d63692e6f72672f4879706172696f2f436f6e7461696e65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Hypario/Container)[![Coverage Status](https://camo.githubusercontent.com/01ca72aa9c3dd67ba3b1b471456b73a830dc1c4a7ab0c025fbb50f694a4217eb/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f4879706172696f2f436f6e7461696e65722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Hypario/Container?branch=master)

What is this ?
==============

[](#what-is-this-)

This library is a Dependency Injection Container written in PHP. I created this library to learn and using PHP-DI as an exemple

How to use it ?
===============

[](#how-to-use-it-)

First you have to create a container builder that will build your container

```
$builder = new Hypario\Builder();
$container = $builder->build();
```

then you can use the container to instantiate a class.

for exemple :

```
class A {
    public function hello() {
        return "Hello World !";
    }
}

$builder = new Hypario\Builder();
$container = $builder->build();

$class = $container->get(A::class);

echo $class->hello(); // output : "Hello World !"
```

the container will instantiate the class

But what if i have a constructor ?
----------------------------------

[](#but-what-if-i-have-a-constructor-)

Like you would do normally, you sometimes need a constructor for you class, there are different possibilities

With a default value
--------------------

[](#with-a-default-value)

You sometimes need a class with a constructor which have default values, no problem the class will be instantiated with the default values like so :

```
class A {

    private $name;

    public function __construct(string $name = "John") {
        $this->name = $name;
    }

    public function hello() {
        return "Hello $this->name !";
    }
}

$builder = new Hypario\Builder();
$container = $builder->build();

$class = $container->get(A::class);
echo $class->hello(); // output : "Hello John !"
```

With a class
------------

[](#with-a-class)

Sometimes your class need another class to work, no worry, this container can instantiate the class needed (if the constructor use default values OR a class too !)

```
class Address {

    public $address;

    public function __construct() {
        $this->address = 'France, Paris 6e'
    }
}

class Person {

    public $name;

    public $address;

    public function __construct(Address $address, string $name = 'John') {
        $this->name = $nom;
        $this->address = $address;
    }

    public function hello() {
        return "Hello $this->name, you live in $this->address";
    }

}

$builder = new Hypario\Builder();
$container = $builder->build();

$class = $container->get(Person::class);
echo $class->hello(); // output : "Hello John, you live in France, Paris 6e"
```

Definitions
===========

[](#definitions)

The definitions are an array where you define to the container how to instantiate a class, or what function you have to call for a specific word and so, define how your class should be instantiate.

You maybe thought it was strange to use a container builder instead of directly call the container right ? well in fact, before you build the container, you can define some definitions to the container builder like so :

```
$builder = new Hypario\Builder();
$builder->addDefinitions(['foo' => 'bar']);
$container = $builder->build();

echo $container->get('foo'); // output : "bar"
```

here I used the definition like a simple array, but you can use those to instantiate a class where you need an Interface

```
interface testInterface{

    public function hello();

}

class test implements testInterface {

    public $string = "Hello I am the test class";

    public function hello(): string {
        return $this->string;
    }
}

class A {

    public $test;

    public function __construct(testInterface $test){
        $this->test = $test;
    }
}

$builder = new Hypario\Builder();
$builder->addDefinitions([
    testInterface::class => test::class
]);
$container = $builder->build();
$class = $container->get(A::class);
echo $class->test->hello(); // output : "Hello I am the test class
```

As we can't get an instance of an interface, as is defined in the definitions, the container will instantiate the test class which implements the testInterface

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community3

Small or concentrated contributor base

Maturity69

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

Recently: every ~129 days

Total

10

Last Release

1916d ago

PHP version history (2 changes)1.0.1PHP ^7.2

1.1.0PHP ^8.0

### Community

---

Top Contributors

[![Hypario](https://avatars.githubusercontent.com/u/30122807?v=4)](https://github.com/Hypario "Hypario (6 commits)")

### Embed Badge

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

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

PHPackages © 2026

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