PHPackages                             php-simple/constructor-injection - 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. php-simple/constructor-injection

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

php-simple/constructor-injection
================================

Very very simple container example that injects dependency on class constructor.

v1(3y ago)07PHP

Since Feb 1Pushed 3y ago1 watchersCompare

[ Source](https://github.com/atakansn/PHPSimpleConstructorInjection)[ Packagist](https://packagist.org/packages/php-simple/constructor-injection)[ RSS](/packages/php-simple-constructor-injection/feed)WikiDiscussions main Synced 1mo ago

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

PHP Simple Constructor Injection
================================

[](#php-simple-constructor-injection)

Very very simple container example that injects dependency on class constructor

Install
-------

[](#install)

```
  composer require php-simple/constructor-injection
```

Usage/Examples
--------------

[](#usageexamples)

### bind() method

[](#bind-method)

```
require_once __DIR__ . '/vendor/autoload.php';

class User
{
    public $foo;

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

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

class Foo
{
    public function sayFoo()
    {
        return 'Foooo'
    }
}

$container = new \ConstructorInjection\Container();

$container->bind(User::class);

$userInstance = $container->getBinding(User::class)

// Foooo
$userInstance->foo();
```

### bind() method with closure

[](#bind-method-with-closure)

```
$container->bind(User::class,function (){
    return new User();
});

$userInstance = $container->getBinding(User::class)

// Foooo
$userInstance->foo();
```

### get() method

[](#get-method)

```
$userInstance = $container->get(User::class);

// Foooo
$userInstance->foo();
```

### getBindings method()

[](#getbindings-method)

- returns all bind classes

```
$bindings = $container->getBindings();

print_r($bindings);

//Array
//(
//    [User] => Closure Object
//        (
//        )
//
//)
```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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

1200d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1764b2f96c7261e22f977a61f2bf3dfa40ac5df921cf08174f4bb8880040acdc?d=identicon)[atakansn](/maintainers/atakansn)

---

Top Contributors

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

---

Tags

containerdependency-injectionphp

### Embed Badge

![Health badge](/badges/php-simple-constructor-injection/health.svg)

```
[![Health](https://phpackages.com/badges/php-simple-constructor-injection/health.svg)](https://phpackages.com/packages/php-simple-constructor-injection)
```

###  Alternatives

[symfony/dependency-injection

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

4.2k431.1M7.5k](/packages/symfony-dependency-injection)[illuminate/contracts

The Illuminate Contracts package.

704122.9M10.1k](/packages/illuminate-contracts)[illuminate/container

The Illuminate Container package.

31278.1M2.0k](/packages/illuminate-container)[ecotone/ecotone

Supporting you in building DDD, CQRS, Event Sourcing applications with ease.

558549.8k17](/packages/ecotone-ecotone)[civicrm/civicrm-core

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

728272.9k20](/packages/civicrm-civicrm-core)[internal/dload

Downloads binaries.

98142.7k10](/packages/internal-dload)

PHPackages © 2026

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