PHPackages                             jopic/jdi - 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. [Framework](/categories/framework)
4. /
5. jopic/jdi

ActiveLibrary[Framework](/categories/framework)

jopic/jdi
=========

simple dependency injection framework

1.0.0(11y ago)020Apache-2.0PHP

Since Mar 29Pushed 11y ago1 watchersCompare

[ Source](https://github.com/fetzi/jdi)[ Packagist](https://packagist.org/packages/jopic/jdi)[ Docs](https://github.com/fetzi/jdi)[ RSS](/packages/jopic-jdi/feed)WikiDiscussions master Synced 1w ago

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

JDI - Jopic Dependency Injection
================================

[](#jdi---jopic-dependency-injection)

[![Build Status](https://camo.githubusercontent.com/4819ae310b2ed3fbb85976a29409f367ab5bff335bdc0b4ed8fe87ad6a9b3050/68747470733a2f2f7472617669732d63692e6f72672f6665747a692f6a64692e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/fetzi/jdi)

This repository provides a very basic and easy to use dependency injection "framework" for PHP.

Installation
------------

[](#installation)

You basically only need to add the following dependency `"jopic/jdi": "1.0.0"` into your `composer.json` file.

Usage - Container Setup
-----------------------

[](#usage---container-setup)

At first you have to set up your dependency container:

```
$container = new Jopic\DI\Container();
```

Then you can set this container as the active container for dependency injection by:

```
\Jopic\DI\DependencyInjection::getInstance()->setContainer($container);
```

Usage - Container Object registration
-------------------------------------

[](#usage---container-object-registration)

To be able to inject objects to class fields the dependency injection container needs to know about injectable objects. Therefore you register them on the container by calling the `register` method.

```

$container->register("foo", function() {
    return new DummyObject();
});
```

**Please note:** it is important to register a closure function (needed for object instantiation).

Usage - Object Injection
------------------------

[](#usage---object-injection)

Basically the only 3 things you need to do are:

1. extend the abstract `JDIBaseClass`
2. call `parent::__construct($this);` in your class constructor
3. annotate inject fields of your class with `@inject`

Here is a short example of a Injectable class:

```
class SampleClass extends Jopic\DI\JDIBaseClass {
    /**
     * @inject
     */
    private $foo;

    public function __construct() {
        parent::__construct($this);
    }
}
```

This code assures that if a object with the name "foo" is registered in the dependency injection container it will be available in this class instances automatically.

Lazy Injection
--------------

[](#lazy-injection)

If you define a property as protected, the class constructor of JDIBaseClass will automatically inject this property lazily. That means that the property closure gets executed just before the first property usage.

Here is a short example of a class with directly injected and lazily injected properties:

```
class SampleClass extends Jopic\DI\JDIBaseClass {
    /**
     * this value gets injected on constructor call
     * @inject
     */
    private $foo;

    /**
     * this value gets injected just before the first getFoo2() call
     * @inject
     **/
    protected $foo2;

    public function __construct() {
        parent::__construct($this);
    }

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

    public function getFoo2() {
        return $this->foo2;
    }
}
```

Request for comment
-------------------

[](#request-for-comment)

If you find any bugs or if you find something (or everything ;-) ) inconvenient please don't hesitate to contact me either directly via github or via e-mail (admin \[at\] jopic.at).

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity63

Established project with proven stability

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

4090d ago

### Community

Maintainers

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

---

Tags

dependency-injectiondi

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jopic-jdi/health.svg)

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

###  Alternatives

[yiisoft/injector

PSR-11 compatible injector. Executes a callable and makes an instances by injecting dependencies from a given DI container.

943.2M46](/packages/yiisoft-injector)[mouf/mouf

The Mouf PHP framework: an open-source PHP framework providing an easy way to download, install, use and reuse components, with a graphical user interface.

56146.3k17](/packages/mouf-mouf)[mouf/pimple-interop

This project is a very simple extension to the Pimple microframework. It adds to Pimple compatibility with the container-interop APIs.

102.5M2](/packages/mouf-pimple-interop)[joomla/di

Joomla DI Package

16417.5k12](/packages/joomla-di)[mouf/picotainer

This package contains a really minimalist dependency injection container compatible with container-interop.

16190.7k11](/packages/mouf-picotainer)

PHPackages © 2026

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