systream/dependency-injection-container

1.2.1 2017-09-07 22:27 UTC

This package is not auto-updated.

Last update: 2024-11-22 23:31:44 UTC


README

For saving models with repository pattern.

Installation

You can install this package via packagist.org with composer.

composer require systream/dependency-injection-container

composer.json:

"require": {
    "systream/dependency-injection-container": "1.*"
}

This library requires php 5.6 or higher, but also works on php 5.4.

Usage

$di = new DependencyInjectionContainer();
$di->bind(FixtureTestInterface::class, function () {
	return new ObjectA();
});

$di->has(FixtureTestInterface::class); // will return true

$instance = $di->get(FixtureTestInterface::class); // will return ObjectA instance 

Create

class TestObjectB {
	public function __construct(FixtureTestInterface $test) {
	}
}

$di = new DependencyInjectionContainer();
$di->bind(FixtureTestInterface::class, function () {
	return new ObjectA();
});

$testObject = $di->create(TestObjectB::class); 

Test

Build Status