PHPackages                             program-2/reason - 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. program-2/reason

ActiveLibrary

program-2/reason
================

PHP Dependency Injection Container

v2.1.0(7y ago)28Apache-2.0PHPPHP ^7.2

Since Apr 12Pushed 7y agoCompare

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

READMEChangelogDependenciesVersions (3)Used By (0)

Reason A PHP Dependency Injection Class
---------------------------------------

[](#reason--a-php-dependency-injection-class)

### Introduction

[](#introduction)

Reason is a brief dependency injection Class that also supports a direct

object injection system for PHP of 36 lines,

with no need to configuration, that uses reflection.

It can also be used for the last part of

an Inversion of Control (IoC) system to route

a control flow and inputs to their destination.

### Aims

[](#aims)

1- to be as small as possible.

2- to be able to handle the dependency of a dependency.

3- to be fast. reflection is much faster than annotation.

### Instalation

[](#instalation)

Load Reason along with all dependency classes in your project.

### How to use it (3 ways explained)

[](#how-to-use-it-3-ways-explained)

-
-

#### First way

[](#first-way)

(the **recommended way**; beacause it will not occupy

the parameters palce of methods, it only occupies parameters

place of construct method which is allocated for dependency injection purposes.)

1- Put "Reason $Reason" as parameter of the **construc method** of the class:

```
  public function __construct(Reason $Reason)
  {
    //
  }

```

2- Instantiate the Class where/when needed with "Reason":

```
  ((new Reason)->inject('Class'));

```

Inside the construct method you will have access to injected $Reason object

so you can make $Reason available within the class

with programing techniques like using a property to share it:

```
  $Reason->inject('Class');

```

example:

```
 $obj = $Reason->inject('DataBaseClass');

 $obj->query(..);

```

(Here the dependencies of dependencies will also be injected as well)

-
-

#### Second way

[](#second-way)

(calling a method and injecting the type-hinted Reason)

1- Put "Reason $Reason" as parameter of the **method**:

```
  public function Method(Reason $Reason)
  {
    //
  }

```

2- Instantiate the methods where/when needed with "Reason":

```
  ((new Reason)->inject('Class','Method'));

```

Inside the methods use injected $Reason object to get an instance of any dependency:

```
  $Reason->inject('Class','Method');

```

(Here the dependencies of dependencies will also be injected as well)

**Notice:**

As you don't have access to pass parameters to methods directly

in the second way, any needed values can be passed throuth one(1) array of

keys/values as the third(3rd) parameter position:

```
  ((new Reason)->inject('Class', 'Method', array('john'=>'4')));

```

and when injected into objects:

```
  $Reason->inject('Class', 'Method', array('john'=>'4'));

```

then accessible:

```
  $john;

```

-
-

#### Third way

[](#third-way)

( use it for "unlimitted number of direct object injection" only if your dependency

classes themselves are independent so they don't have Reason inside their own class definition.

Please note that Reason itself can be among these type-hinted classes. )

1- Put "AnyDependencyClass $AnyDependencyClass" as parameter of the **method**:

```
  Class
  {
      public function Method(Class1 $Class1, Class2 $Class2, Reason $Reason, ...)
      {
        //
      }
  }

```

2- Instantiate the methods where/when needed with "Reason":

```
  ((new Reason)->inject('Class','Method'));

```

Inside the methods directly use your injected object:

```
  $Class1;

  $Class2;

  $Reason;

```

**Notice:**

It is possible to pass Reason Manually like any of the parameter

of the method if the method accepts any paratemer:

```
 ((new Reason)->inject('Class'))->Method(new Reason);

```

or make it inside a method of a class:

```
 $reason = new Reason;

```

thus reserving the parameters place for the programing purpose,

but ways increase the **coupling degree** a little.

### Credit

[](#credit)

Developed by Ehsan Yousefi  \[\]

### Updates

[](#updates)

" 8/4/2019 1.0.0 first release" - Backwards incompatible

"25/4/2019 2.0.0 new features added &gt;&gt; ways(No.1 &amp; No.3)" - Backwards incompatible

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 76.2% 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 ~19 days

Total

2

Last Release

2573d ago

Major Versions

v1.0.2 → v2.1.02019-05-01

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/49523862?v=4)[Ehsan Yousefi](/maintainers/program-2)[@program-2](https://github.com/program-2)

---

Top Contributors

[![program-2](https://avatars.githubusercontent.com/u/49523862?v=4)](https://github.com/program-2 "program-2 (16 commits)")[![fsdeveloper1](https://avatars.githubusercontent.com/u/39985806?v=4)](https://github.com/fsdeveloper1 "fsdeveloper1 (5 commits)")

---

Tags

dependencyreason

### Embed Badge

![Health badge](/badges/program-2-reason/health.svg)

```
[![Health](https://phpackages.com/badges/program-2-reason/health.svg)](https://phpackages.com/packages/program-2-reason)
```

###  Alternatives

[composer/composer

Composer helps you declare, manage and install dependencies of PHP projects. It ensures you have the right stack everywhere.

29.4k187.2M2.6k](/packages/composer-composer)[league/container

A fast and intuitive dependency injection container.

86387.8M343](/packages/league-container)[maglnet/composer-require-checker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

99810.9M671](/packages/maglnet-composer-require-checker)[bamarni/composer-bin-plugin

No conflicts for your bin dependencies

52722.0M859](/packages/bamarni-composer-bin-plugin)[php-di/invoker

Generic and extensible callable invoker

26857.8M56](/packages/php-di-invoker)[yiisoft/di

Yii DI container

2351.2M100](/packages/yiisoft-di)

PHPackages © 2026

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