2017 © Pedro Peláez
 

library automatic-di

image

midnight/automatic-di

  • Tuesday, July 3, 2018
  • by MidnightDesign
  • Repository
  • 1 Watchers
  • 0 Stars
  • 880 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 4 Versions
  • 68 % Grown

The README.md

midnight/automatic-di

Build Status, (*1)

This package provides automatic dependency injection for PHP. It requires a container-interop-compatible container., (*2)

Installation

Composer: midnight/automatic-di, (*3)

Usage

Let's say we have the following interfaces and classes:, (*4)

interface FooInterface {
}

class Foo {
    private $bar;
    public function __construct(Bar $bar) {
        $this->bar = $bar;
    }
}

class Bar {
}

interface BazInterface {
}

class Baz {
}

class Hodor {
    private $baz;
    public function __construct(BazInterface $baz) {
        $this->baz = $baz;
    }
}

Now we can use the AutomaticDiContainer like this:, (*5)

$wrappedContainer = new Some\Other\Container; // An implementation of Interop\Container\ContainerInterface
$config = Midnight\AutomaticDi\AutomaticDiConfig::fromArray([
    'preferences' => [
        FooInterface::class => Foo::class,
    ],
    'classes' => [
        Hodor::class => [
            'baz' => Baz::class,
        ],
    ],
]);
$container = new Midnight\AutomaticDi\AutomaticDiContainer($wrappedContainer, $config);

$foo = $container->get(FooInterface::class); // Returns an instance of Foo
$hodor = $container->get(Hodor::class); // Returns an instance of Hodor with an injected Baz

Performance

This package works via reflection. Isn't that slow?, (*6)

Yes, it is. A cache is coming soon., (*7)

The Versions

03/07 2018

dev-php5.5

dev-php5.5

  Sources   Download

MIT

The Requires

 

The Development Requires

06/12 2016

dev-cache

dev-cache

  Sources   Download

MIT

The Requires

 

The Development Requires

06/12 2016

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

The Development Requires

13/09 2016

v1.0.0

1.0.0.0

  Sources   Download

MIT

The Requires

 

The Development Requires