PHPackages                             romeoz/rock-di - 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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. romeoz/rock-di

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

romeoz/rock-di
==============

Small and flexible Dependency Injection library for PHP

0.14.0(10y ago)082711MITPHPPHP &gt;=5.4.0

Since Jan 27Pushed 10y ago1 watchersCompare

[ Source](https://github.com/romeOz/rock-di)[ Packagist](https://packagist.org/packages/romeoz/rock-di)[ RSS](/packages/romeoz-rock-di/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (11)Used By (1)

Dependency Injection library for PHP
====================================

[](#dependency-injection-library-for-php)

[![Latest Stable Version](https://camo.githubusercontent.com/f28b1b73bd71688498d1ffcfae80fac20be5e1223c409c84a3ed34e500d36a40/68747470733a2f2f706f7365722e707567782e6f72672f726f6d654f7a2f726f636b2d64692f762f737461626c652e737667)](https://packagist.org/packages/romeOz/rock-di)[![Total Downloads](https://camo.githubusercontent.com/2f448efba0688913942de9ca96c3e6c84be079587ea7016cf789a11740887881/68747470733a2f2f706f7365722e707567782e6f72672f726f6d654f7a2f726f636b2d64692f646f776e6c6f6164732e737667)](https://packagist.org/packages/romeOz/rock-di)[![Build Status](https://camo.githubusercontent.com/88bf53a4538cbef36d147dc584290aec6176d5c2f49eb703460dc8d7ebf5c0c4/68747470733a2f2f7472617669732d63692e6f72672f726f6d654f7a2f726f636b2d64692e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/romeOz/rock-di)[![HHVM Status](https://camo.githubusercontent.com/e2b06fba0bebca164010486c0abc686043fef056aa6b813126ded76a50acf00a/687474703a2f2f6868766d2e683463632e64652f62616467652f726f6d656f7a2f726f636b2d64692e737667)](http://hhvm.h4cc.de/package/romeoz/rock-di)[![Coverage Status](https://camo.githubusercontent.com/dd984569a348eba8534eccef49a288e7c5aed25f35451530a1d5b4c9cc3b96e8/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f726f6d654f7a2f726f636b2d64692f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/r/romeOz/rock-di?branch=master)[![License](https://camo.githubusercontent.com/d998cc111b7d430da6b52b29e930d38bc45ec9e15ed1084d02c7d6cd7da56b01/68747470733a2f2f706f7365722e707567782e6f72672f726f6d654f7a2f726f636b2d64692f6c6963656e73652e737667)](https://packagist.org/packages/romeOz/rock-di)

Features
--------

[](#features)

- Service locator
- Constructor injection
- Support singleton
- Standalone module/component for [Rock Framework](https://github.com/romeOz/rock)

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

[](#installation)

From the Command Line:

```
composer require romeoz/rock-di

```

In your composer.json:

```
{
    "require": {
        "romeoz/rock-di": "*"
    }
}
```

Quick Start
-----------

[](#quick-start)

```
namespace test;

use rock\di\Container;

class Foo
{

}

$config = [
    'class' => '\test\Foo',
    // 'singleton' => true,   // if you want to return singleton
 ];
$alias = 'foo' ;  // short alias
Container::register($alias, $config);

$foo = Container::load('foo');
```

\####Constructor injection

```
namespace test;

use rock\di\Container;

class Foo
{

}

class Bar
{
    public $foo;

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

$config = [
    'class' => '\test\Foo',
 ];
Container::register('foo' , $config);

$config = [
    'class' => '\test\Bar',
 ];
Container::register('bar' , $config);

$bar = Container::load('bar');
$bar->foo instanceof Bar; // output: true
```

\####Configure properties

```
namespace test;

use rock\di\Container;
use rock\base\ObjectInterface;
use rock\base\ObjectTrait;

class Foo implements ObjectInterface
{
    use ObjectTrait;

    public $name;
}

$config = [
    'class' => '\test\Foo',

    // properties
    'name' => 'Tom'
 ];

Container::register('foo', $config);

$foo = Container::load('foo');

echo $foo->name; // output: Tom
```

Configure properties through setters and getters:

```
namespace test;

use rock\di\Container;
use rock\base\ObjectInterface;
use rock\base\ObjectTrait;

class Foo implements ObjectInterface
{
    use ObjectTrait;

    private $name;

    public function setName($name)
    {
        $this->name = $name;
    }

    public function getName()
    {
        return $this->name;
    }

}

$config = [
    'class' => '\test\Foo',

    // properties
    'name' => 'Tom'
 ];

Container::register('foo', $config);

$foo = Container::load('foo');

echo $foo->name; // output: Tom
```

Requirements
------------

[](#requirements)

- **PHP 5.4+**

License
-------

[](#license)

The Rock Dependency Injection is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity54

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

Total

10

Last Release

3842d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/23c5d84a59845d751cb69f5469986579b9312c54c898b366fefdc05baaa80a9c?d=identicon)[romeOz](/maintainers/romeOz)

---

Top Contributors

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

---

Tags

containerdependency-injectiondi

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/romeoz-rock-di/health.svg)

```
[![Health](https://phpackages.com/badges/romeoz-rock-di/health.svg)](https://phpackages.com/packages/romeoz-rock-di)
```

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.8k48.9M994](/packages/php-di-php-di)[aura/di

A serializable dependency injection container with constructor and setter injection, interface and trait awareness, configuration inheritance, and much more.

356968.3k58](/packages/aura-di)[mrclay/props-dic

Props is a simple DI container that allows retrieving values via custom property and method names

3611.7M3](/packages/mrclay-props-dic)[slince/di

A flexible dependency injection container

20260.4k6](/packages/slince-di)[capsule/di

A PSR-11 compliant autowiring dependency injection container.

2857.5k2](/packages/capsule-di)

PHPackages © 2026

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