PHPackages                             monotek/dependency-inject - 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. monotek/dependency-inject

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

monotek/dependency-inject
=========================

Tried and tested minimal dependency injection for PHP

v1.0.1(9y ago)149MITPHPPHP &gt;=5.3.0

Since Nov 24Pushed 9y ago1 watchersCompare

[ Source](https://github.com/titpetric/monotek-dependency-inject)[ Packagist](https://packagist.org/packages/monotek/dependency-inject)[ Docs](https://github.com/titpetric/monotek-dependency-inject)[ RSS](/packages/monotek-dependency-inject/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (3)Used By (0)

Dependency injection with PHP
=============================

[](#dependency-injection-with-php)

Simply, this package consists of two classes. Class `Dependency` handles the definition of dependencies and resources. Class `Inject` handles auto injection of defined dependencies when instantiating objects.

Defining a dependency is as simple as:

```
Dependency::set("database", function($param = false) {
	return new Database();
});

```

Using a dependency is as simple as:

```
class UsesDatabase extends Inject
{
	public $inject = array("database");
	public function process()
	{
		$db = $this->getDatabase("param");
	}
}

```

The defined dependencies will create instances only when they are actually used. If the dependency is not used it will not be instantiated, keeping your overhead when executing PHP code as minimal as possible.

Passing arguments to the dependencies is enabled. This way you can have a utility dependency instantiator, which would return data depending on the arguments.

If you want to override a dependency in an instance:

```
$object->setDatabase($object_or_callback);

```

Every next call to `getDatabase` will return the result of the call or the value which was passed to `setDatabase`.

Please see the unit tests for more advanced examples of using this package.

2014 (c) Tit Petrič, Monotek d.o.o.

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

Every ~649 days

Total

2

Last Release

3590d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

phpdependencyinjectionditinysmallmonotek

### Embed Badge

![Health badge](/badges/monotek-dependency-inject/health.svg)

```
[![Health](https://phpackages.com/badges/monotek-dependency-inject/health.svg)](https://phpackages.com/packages/monotek-dependency-inject)
```

###  Alternatives

[php-di/invoker

Generic and extensible callable invoker

26764.7M69](/packages/php-di-invoker)[marcelog/ding

PHP Dependency Injection based on Spring(tm), with Aspect Oriented Programming, MVC

1192.1k](/packages/marcelog-ding)[monotek/minitpl

Miniature fully featured PHP template engine

125.5k1](/packages/monotek-minitpl)

PHPackages © 2026

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