2017 © Pedro Peláez
 

library di

g4 dependencies injection container based on Pimple

image

g4/di

g4 dependencies injection container based on Pimple

  • Thursday, March 8, 2018
  • by g4code
  • Repository
  • 13 Watchers
  • 0 Stars
  • 11,847 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 8 Versions
  • 9 % Grown

The README.md

DI

DI - dependencies injection container - singleton Pimple wrapper https://github.com/silexphp/Pimple, (*1)

  • easy access by a method not by an array property
  • no need to remember DI array keys (or go back to the DI class to look) every time you need something
  • type hinting

Install

Using Composer and Packagist https://packagist.org/packages/g4/di, (*2)

composer require g4/di

Usage

Services are defined by anonymous functions that returns an instance of an object. Define all services in one DI Container class inside your application:, (*3)


namespace MyNamespace; use G4\DI\Container; class DI extends Container { /** * @return \MyNamespace\MyConfig */ public static function configInstance() { return self::registerShare(function (DI $c) { return new \MyNamespace\MyConfig(); }); } /** * @return \MyNamespace\MyClass */ public static function myClassInstance() { return self::registerFactory(function (DI $c) { return new \MyNamespace\MyClass($c::configInstance()); }); } }

Methods * registerFactory($callable) - Register a service that will each time return new instance of it * registerShare($callable) - Register a service that will each time return the same instance of it, (*4)

Using the defined services, (*5)


use MyNamespace\DI; $myClass = DI::myClassInstance(); // the above call is equivalent to: // $myConfig = new \MyNamespace\MyConfig(); // $myClass = new \MyNamespace\MyClass($myConfig);

Development

Install dependencies

$ make install

Run tests

$ make test

License

(The MIT License) see LICENSE file for details..., (*6)

The Versions

08/03 2018

dev-master

9999999-dev

g4 dependencies injection container based on Pimple

  Sources   Download

MIT

The Requires

 

by Drasko Gomboc
by Dejan Samardzija
by Ivan Krickovic

di pimple dependencies

08/03 2018

1.0.1

1.0.1.0

g4 dependencies injection container based on Pimple

  Sources   Download

MIT

The Requires

 

by Drasko Gomboc
by Dejan Samardzija
by Ivan Krickovic

di pimple dependencies

30/09 2015

dev-develop

dev-develop

g4 dependencies injection container based on Pimple

  Sources   Download

MIT

The Requires

 

by Drasko Gomboc
by Dejan Samardzija
by Ivan Krickovic

di pimple dependencies

28/09 2015

1.0.0

1.0.0.0

g4 dependencies injection container based on Pimple

  Sources   Download

MIT

The Requires

 

by Drasko Gomboc
by Dejan Samardzija
by Ivan Krickovic

di pimple dependencies

26/06 2015

0.2.0

0.2.0.0

g4 dependencies injection container based on Pimple

  Sources   Download

MIT

The Requires

 

by Drasko Gomboc
by Dejan Samardzija
by Ivan Krickovic

di pimple dependencies

08/07 2014

0.1.2

0.1.2.0

g4 dependencies injection container based on Pimple

  Sources   Download

MIT

The Requires

 

by Drasko Gomboc
by Dejan Samardzija
by Ivan Krickovic

di pimple dependencies

16/05 2014

0.1.1

0.1.1.0

g4 dependencies injection container based on Pimple

  Sources   Download

MIT

The Requires

 

by Drasko Gomboc
by Dejan Samardzija
by Ivan Krickovic

di pimple dependencies

27/04 2014

0.1.0

0.1.0.0

g4 dependencies injection container based on Pimple

  Sources   Download

MIT

The Requires

 

by Drasko Gomboc
by Dejan Samardzija
by Ivan Krickovic

di pimple dependencies