carousel/container

Dependency Injection container for PHP projects

v1.0.0 2017-02-23 09:07 UTC

This package is not auto-updated.

Last update: 2024-12-21 19:43:06 UTC


README

#Simple dependency injection container for PHP projects Build Status

Installation

With Composer

$ composer require carousel/container

composer.json

{
    "require": {
        "carousel/container": "0.4.0"
    }
}

Usage

//bind object into the container (using ArrayAccess)
$this->container['car'] = function () { return new Car(); };

//resolve
$car = $this->container['car'];

//call object method
$car->setMake('VW');

//swap binding key
$this->container->swapKey('car', 'new_car');

//resolve
$new_car = $this->container['new_car'];