flamecore/container

Simple and lightweight Dependency Injection Container

v1.0.0 2015-09-14 17:47 UTC

README

Build Status Scrutinizer Coverage License

This library provides a simple and lightweight Dependency Injection Container.

Features

  • Interfaces: Extended container interfaces compatible with container-interop

    • EditableContainerInterface

    • LockableContainerInterface

  • Classes: Advanced and feature-complete container implementations based on the interfaces

    • EditableContainer

    • LockableContainer

Usage

To make use of the API, include the vendor autoloader and use the classes:

namespace Acme\MyApplication;

use FlameCore\Container\EditableContainer;

$container = new EditableContainer();

You can define() items to require a value type. To assign values to items, use the set() method.

$container->define('bar', 'Acme\MyApplication\Config'); // or 'Config::class'
$container->set('bar', new Config());
$container->has('bar');
$container->get('bar');

This works also with arrays and scalar types:

$container->define('foo', ':string');
$container->set('foo', 'bar');

Installation

Install via Composer

Install Composer if you don't already have it present on your system:

$ curl -sS https://getcomposer.org/installer | php

To install the library, run the following command and you will get the latest version:

$ composer require flamecore/container

Requirements

  • You must have at least PHP version 5.4 installed on your system.

Contributors

If you want to contribute, please see the CONTRIBUTING file first.

Thanks to the contributors:

  • Christian Neff (secondtruth)