2017 © Pedro Peláez
 

library rock-di

Small and flexible Dependency Injection library for PHP

image

romeoz/rock-di

Small and flexible Dependency Injection library for PHP

  • Monday, November 9, 2015
  • by romeOz
  • Repository
  • 1 Watchers
  • 0 Stars
  • 774 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 0 % Grown

The README.md

Dependency Injection library for PHP

Latest Stable Version Total Downloads Build Status HHVM Status Coverage Status License, (*1)

Features

  • Service locator
  • Constructor injection
  • Support singleton
  • Standalone module/component for Rock Framework

Installation

From the Command Line:, (*2)

composer require romeoz/rock-di

In your composer.json:, (*3)

{
    "require": {
        "romeoz/rock-di": "*"
    }
}

Quick Start

namespace test;

use rock\di\Container;

class Foo 
{

}

$config = [
    'class' => '\test\Foo', 
    // 'singleton' => true,   // if you want to return singleton
 ];
$alias = 'foo' ;  // short alias
Container::register($alias, $config);

$foo = Container::load('foo');

Constructor injection

namespace test;

use rock\di\Container;

class Foo 
{

}

class Bar 
{
    public $foo;

    public function __construct(Foo $foo)
    {
        $this->foo = $foo;
    }
}

$config = [
    'class' => '\test\Foo',
 ];
Container::register('foo' , $config);

$config = [
    'class' => '\test\Bar',
 ];
Container::register('bar' , $config);

$bar = Container::load('bar');
$bar->foo instanceof Bar; // output: true

Configure properties

namespace test;

use rock\di\Container;
use rock\base\ObjectInterface;
use rock\base\ObjectTrait;

class Foo implements ObjectInterface
{
    use ObjectTrait;

    public $name;
}

$config = [
    'class' => '\test\Foo', 

    // properties
    'name' => 'Tom'
 ];

Container::register('foo', $config);

$foo = Container::load('foo');

echo $foo->name; // output: Tom 

Configure properties through setters and getters:, (*4)

namespace test;

use rock\di\Container;
use rock\base\ObjectInterface;
use rock\base\ObjectTrait;

class Foo implements ObjectInterface
{
    use ObjectTrait;

    private $name;

    public function setName($name)
    {
        $this->name = $name;
    }

    public function getName()
    {
        return $this->name;
    }

}

$config = [
    'class' => '\test\Foo', 

    // properties
    'name' => 'Tom'
 ];

Container::register('foo', $config);

$foo = Container::load('foo');

echo $foo->name; // output: Tom 

Requirements

  • PHP 5.4+

License

The Rock Dependency Injection is open-sourced software licensed under the MIT license., (*5)

The Versions

09/11 2015

dev-master

9999999-dev

Small and flexible Dependency Injection library for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

dependency injection container di

09/11 2015

0.14.0

0.14.0.0

Small and flexible Dependency Injection library for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

dependency injection container di

18/10 2015

0.12.2

0.12.2.0

Small and flexible Dependency Injection library for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

dependency injection container di

10/07 2015

0.12.1

0.12.1.0

Small and flexible Dependency Injection Container for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

dependency injection container di

10/07 2015

0.12.0

0.12.0.0

Small and flexible Dependency Injection Container for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

dependency injection container di

06/07 2015

0.11.1

0.11.1.0

Small and flexible Dependency Injection Container for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

dependency injection container di

06/07 2015

0.11.0

0.11.0.0

Small and flexible Dependency Injection Container for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

dependency injection container di

12/06 2015

0.10.2

0.10.2.0

Small and flexible Dependency Injection Container for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

dependency injection container di

15/03 2015

0.10.1

0.10.1.0

Small and flexible Dependency Injection Container for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

dependency injection container di

05/03 2015

0.10.0

0.10.0.0

Small and flexible Dependency Injection Container for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

dependency injection container di

27/01 2015

0.9.0

0.9.0.0

Small and flexible Dependency Injection Container for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

dependency injection container di