2017 © Pedro Peláez
 

library viocon

A simple and flexible Dependency Injection container for PHP.

image

usmanhalalit/viocon

A simple and flexible Dependency Injection container for PHP.

  • Saturday, July 13, 2013
  • by usmanhalalit
  • Repository
  • 2 Watchers
  • 2 Stars
  • 61,422 Installations
  • PHP
  • 6 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 4 Versions
  • 23 % Grown

The README.md

Viocon Build Status

A simple and flexible Dependency Injection or Service container for PHP., (*1)

It can be extremely helpful to decouple your dependencies. You can also mock dependencies at runtime., (*2)

Installation

Viocon uses Composer to make things easy., (*3)

Learn to use composer and add this to require (in your composer.json):, (*4)

"usmanhalalit/viocon": "1.0.*@dev"

Library on Packagist., (*5)

Usage

$container = new \Viocon\Container();

You can optionally create a class alias too, (*6)

new \Viocon\Container('Container');

Viocon will create a class alias for you with the given name 'Container'. Now you can use this class' methods statically, like, (*7)

\Container::set(...);
\Container::build(...);

And so ..., (*8)


Bind a closure

$container->set('myClosure', function ($test1, $test2) 
{
    $stdClass = new \stdClass();
    $stdClass->testVar1 = $test1;
    $stdClass->testVar2 = $test2;
    $stdClass->testMethod = function ($test3) {
        return $test3;
    };

    return $stdClass;
});

$object = $container->build('myClosure', array('Test Var 1', 'Test Var 2'))

echo $object->testVar1;

Build Any Class and Optionally Pass Parameters

$container->build('\PDO', array('myConnectionInfo'));

Singleton

$container->set('mySingleton', '\\stdClass');
$stdClass = $container->build('mySingleton');

Replacing Objects at Runtime

It can be useful while testing with mocked object, (*9)

$mockedClass = new \stdClass();
$mockedClass->testVar = 'mocked';

static::$container->setInstance('\\stdClass', $mockedClass);

$stdClass = static::$container->build('\\stdClass');
$this->assertEquals('mocked', $stdClass->testVar);

The Versions

13/07 2013

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/usmanhalalit/viocon

A simple and flexible Dependency Injection container for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Muhammad Usman

test container ioc di

13/07 2013

dev-master

9999999-dev https://github.com/usmanhalalit/viocon

A simple and flexible Dependency Injection container for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Muhammad Usman

test container ioc di

13/07 2013

1.0.1

1.0.1.0 https://github.com/usmanhalalit/viocon

A simple and flexible Dependency Injection container for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Muhammad Usman

test container ioc di

09/07 2013

1.0.0

1.0.0.0 https://github.com/usmanhalalit/viocon

A simple and flexible Dependency Injection container for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Muhammad Usman

test container ioc di