PHPackages                             nayjest/di-hub - 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. nayjest/di-hub

ActiveLibrary

nayjest/di-hub
==============

Dependency injection library for PHP with links consistency maintaining mechanism

v0.1.0(9y ago)1411[6 issues](https://github.com/Nayjest/di-hub/issues)MITPHPPHP ^5.5||^7

Since Feb 7Pushed 8y ago1 watchersCompare

[ Source](https://github.com/Nayjest/di-hub)[ Packagist](https://packagist.org/packages/nayjest/di-hub)[ RSS](/packages/nayjest-di-hub/feed)WikiDiscussions master Synced 2mo ago

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

DI-Hub (Dependency Injection Hub)
=================================

[](#di-hub-dependency-injection-hub)

IoC container for PHP with hierarchy and links consistency maintaining mechanism

[![Build Status](https://camo.githubusercontent.com/72a0479fe273c21401b31a55d7d27faca23489e8a3b8cc12c4cdb16e42ec3465/68747470733a2f2f7472617669732d63692e6f72672f4e61796a6573742f64692d6875622e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Nayjest/di-hub)

[![SensioLabsInsight](https://camo.githubusercontent.com/dd0cee46a31f6c62c5b2730dcda04d028e85c3a622026dd36b461f4461e416de/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f32643362643033382d303431312d346261372d626532352d3832613832336539306637362f6269672e706e67)](https://insight.sensiolabs.com/projects/2d3bd038-0411-4ba7-be25-82a823e90f76)

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [Testing](#testing)
- [Contributing](#contributing)
- [Security](#security)
- [License](#license)

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

[](#requirements)

- PHP 5.5+ (HHVM &amp; PHP7 are supported)

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

[](#installation)

The recommended way of installing this package is through [Composer](https://getcomposer.org).

Run following command from your project folder:

```
composer require nayjest/di-hub
```

Usage
-----

[](#usage)

### Creating hub

[](#creating-hub)

Class Nayjest\\DI\\Hub represents IoC container. This class implements ContainerInterface from container-interop/container-interop package.

Hub can be instantiated without arguments or with array containing definitions.

```
use Nayjest\DI\Hub;
# Empty hub
$hub = new Hub;

# Hub with definitions

$hub = new Hub([
  new Value('item1', $item1),
  new Value('item2', $item2),
  new Relation('item1', 'item2', $handler),
]);
```

### Definitions

[](#definitions)

There are several types of definitions that can be added to hub:

- Values
- Relations
- Items

Definitions should implement `Nayjest\DI\Definition\DefinitionInterface`. This intarface don't contains any methods, it's used only to signalize that instances of target class defines data or relations inside container.

Definitions can be added to container(hub) in following ways:

1. Inject array of definition instances into hub constructor
2. Add definition instance to existing hub via `$hub->addDefinition(DefinitionInterface $definition)`
3. Add array of definition instances to existing hub via `$hub->addDefinitions(DefinitionInterface[] $definitions)`
4. Create definitions via DefinitionBuilder: `$hub->builder()->define($id $source)`

#### Value Definitions

[](#value-definitions)

Instance of Nayjest\\DI\\Definition\\Value represent single value in container that can be accessed by it's id. Nayjest\\DI\\Definition\\Value accepts two arguments: id and source. source can contain value to store inside hub or callable that returns target value.

```
# Add data directly to definition
$hub->addDefinition(new Value('item1', $data));

# Add data via callable
$hub->addDefinition(new Value('item2', function(){
   return $data;
}));
```

#### Relation Definitions

[](#relation-definitions)

@todo

#### Item Definitions

[](#item-definitions)

Item is a combination of value &amp; it's initial dependencies. May be useful to store class instances that require DI in constructor.

@todo

### Hierarchy of hubs

[](#hierarchy-of-hubs)

@todo

Testing
-------

[](#testing)

This package bundled with unit tests (PHPUnit).

1. Install nayjest/di-hub as stand-alone project

```
composer create-project nayjest/di-hub -s dev
```

2. Run tests from package folder

```
cd di-hub
composer test
```

Also it's possible to check code style (PSR-2):

```
composer code-style
```

Contributing
------------

[](#contributing)

Please see [Contributing Guidelines](contributing.md) and [Code of Conduct](code_of_conduct.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

License
-------

[](#license)

© 2016—2017 Vitalii Stepanenko

Licensed under the MIT License.

Please see [License File](LICENSE) for more information.

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

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

3380d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

dependency-injectiondiinversion-of-controliocioc-containerphpphp-librarydi containerdependency-injectiondiiocservice providerinversion of controlservice locatorioc-container

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/nayjest-di-hub/health.svg)

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

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.8k48.9M995](/packages/php-di-php-di)[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.

55146.0k17](/packages/mouf-mouf)[level-2/dice

A minimalist Dependency injection container (DIC) for PHP. Please note: 3.0+ is only compatible with PHP 7.0. The 2.0 branch is compatbile with PHP 5.6.

437730.3k17](/packages/level-2-dice)[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)[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)
