2017 © Pedro Peláez
 

library dependency-container

The NiletPHP dependency injection container.

image

niletphp/dependency-container

The NiletPHP dependency injection container.

  • Saturday, April 21, 2018
  • by tsvetelin
  • Repository
  • 1 Watchers
  • 0 Stars
  • 27 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

PHP dependency injection container

Dependency container which provides an easy way for managing dependencies in your PHP projects., (*1)

Requirements

PHP >= 7.0, (*2)

Install

Composer, (*3)

{
    "require": {
        "niletphp/dependency-container": ">=v1.0"
    }
}

Examples

$dc = new Nilet\Components\Container\DependencyContainer();

Resolve dependencies for a given concrete and return a new instance of it, (*4)

$dc->create("Nilet\Foo");

Bind a concrete to interface. Resolving such binding will always return new concrete instance, (*5)

$dc->bind("Nilet\FooInterface", "Nilet\Foo");
$dc->bind("Nilet\FooInterface", function ($dc) {
    return new Nilet\Foo();
});
$dc->create("Nilet\FooInterface");

Share a concrete (singleton)., (*6)

$dc->share("Nilet\Foo");
$dc->share("Nilet\Foo", function ($dc) {
    return new Nilet\Foo();
});

Binding a concrete (singleton) to an Interface, (*7)

$dc->bindShared("Nilet\FooInterface", "Nilet\Foo");
$dc->bindShared("Nilet\FooInterface", function ($dc) {
    return new Nilet\Foo();
});

Register a concrete instance (singleton)., (*8)

$foo = new Nilet\Foo();
$dc->instance("Nilet\Foo", $foo);

Retrieve a concrete., (*9)

$dc->get("Nilet\Foo");

$dc->bindShared("Nilet\FooInterface", "Nilet\Foo");
$dc->get("Nilet\FooInterface");

Determine if a given concrete (singleton) has been resolved., (*10)

$dc->bindShared("Nilet\FooInterface", "Nilet\Foo");
$dc->get("Nilet\FooInterface");
if ($dc->isResolved("Nilet\FooInterface")) { // evaluates to true
    // do something
} else {
    // do something else
}

Determine if a given concrete is shared., (*11)

$dc->share("Nilet\Foo");
if ($dc->isShared("Nilet\Foo")) { // evaluates to true
    // do something
} else {
    // do something else
}

Determine if a given interface is bound., (*12)

$dc->bind("Nilet\FooInterface", "Nilet\Foo");
if ($dc->isBound("Nilet\FooInterface")) { //evaluates to true
    // do something
} else {
    // do something else
}

Determine if a given interface is bound/shared., (*13)

$dc->bindShared("Nilet\FooInterface", "Nilet\Foo");
if ($dc->isBoundShared("Nilet\FooInterface")) { //evaluates to true
    // do something
} else {
    // do something else
}

The Versions

21/04 2018

dev-master

9999999-dev

The NiletPHP dependency injection container.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Tsvetelin Tsonev

21/04 2018

v1.0.0

1.0.0.0

The NiletPHP dependency injection container.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Tsvetelin Tsonev