2017 © Pedro Peláez
 

library container

An IoC container for PHP: simple, fast, clean.

image

php-packages/container

An IoC container for PHP: simple, fast, clean.

  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Container Build Status

An IoC container for PHP: simple, fast, clean., (*1)

Features

  • injecting via type-hinting
  • injecting via property annotations
  • manual dependencies injecting via an array

Installation

composer require php-packages/container

Usage

mixed make(string|mixed $class, array $dependencies = [])

class A
{
}

get_class(container()->make("A")); # => "A"
get_class(container()->make(new A)); # => "A"

class B
{

    public function __construct(array $foo = [], A $bar)
    {
        var_dump($foo); # => []
        get_class($bar); # => "A"
    }
}

container()->make("B");

class C
{

    public function __construct(array $foo)
    {
        var_dump($foo); # => [1, 2, "C"]
    }
}

container()->make("C", [[1, 2, raw("C")]]);

object inject(object $instance)

The inject method be always called inside of make., (*2)

class C
{
}

class A
{

    /**
     * @shouldBeInjected
     * @var C
     */
    public $b;
}

get_class(container()->inject(new A)->b); # => "C"

void bind(string $binding, string|object $value)

container()->bind("foo", "stdClass");
container()->bind("bar", $bar = new stdClass);

var_dump(container()->make("foo")); # => an instance of stdClass
var_dump(container()->make("bar") === container()->make("bar")); # => true

Development

make run-tests
make coverage-report coverage-report-server

Additional information

Container is released under the MIT license., (*3)

The Versions

19/02 2015

dev-master

9999999-dev

An IoC container for PHP: simple, fast, clean.

  Sources   Download

MIT

The Development Requires

dependency injection container ioc inversion of control

19/02 2015

1.2.0

1.2.0.0

An IoC container for PHP: simple, fast, clean.

  Sources   Download

MIT

The Development Requires

dependency injection container ioc inversion of control

09/02 2015

1.1.1

1.1.1.0

An IoC container for PHP: simple, fast, clean.

  Sources   Download

MIT

The Development Requires

dependency injection container ioc inversion of control

06/02 2015

1.1.0

1.1.0.0

An IoC container for PHP: simple, fast, clean.

  Sources   Download

MIT

The Development Requires

dependency injection container ioc inversion of control

02/02 2015

1.0.0

1.0.0.0

An IoC container for PHP: simple, fast, clean.

  Sources   Download

MIT

The Development Requires

dependency injection container ioc inversion of control