2017 © Pedro Peláez
 

library container

Dependency injection container component designed for ease of use and speed. Built for Trident. Heavily inspired by Pimple.

image

strident/container

Dependency injection container component designed for ease of use and speed. Built for Trident. Heavily inspired by Pimple.

  • Friday, March 20, 2015
  • by Seer
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Container

Build Status Coverage Code Climate, (*1)

Dependency injection container component designed for ease of use and speed. Built for Trident. Heavily inspired by [Pimple][1]., (*2)

Installation

Installation is available via Composer. Add the package to your composer.json:, (*3)

$ composer require strident/container ~2.0

Usage

The container is incredibly simple to instantiate. Simply do the following:, (*4)

use Strident\Container\Container;

$container = new Container();

Defining Services

From there, you can define services like so:, (*5)

// 'Service' class defined somewhere, and 'dependency_name' service defined

$container->set("service_name", function($container) {
    return new Service($container->get("dependency_name"));
});

The services are lazy loaded (i.e. nothing is instantiated until it is called)., (*6)

Extending a Service After Definition

You may also extend services once they have been defined (for example, if you wish to augment a service, alter settings, swap out dependencies etc). But note that once a service is used, it becomes locked and cannot be modified further., (*7)

$container->extend("service_name", function($service, $container) {
    $service->doSomething();
    $service->addSomething($container->get("dependency_name"));

    return $service;
});

Defining Factory Services

If you wish to return a new instance of your service every time instead of the same instance, you may define a factory service like so:, (*8)

$container->set("service_name", $container->factory(function($container) {
    return new Service($container->get("dependency_name"));
}));

Parameters

Parameters are get / set by accessing the container like an array:, (*9)

// Set
$container["foo"] = "A parameter can be anything";

// Get
$foo = $container["foo"];

The Versions

20/03 2015

dev-master

9999999-dev https://github.com/Strident/Container

Dependency injection container component designed for ease of use and speed. Built for Trident. Heavily inspired by Pimple.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

component dic trident strident

21/02 2015

2.0.0

2.0.0.0 https://github.com/Strident/Container

Dependency injection container component designed for ease of use and speed. Built for Trident. Heavily inspired by Pimple.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

component dic trident strident

16/02 2015

1.0.0

1.0.0.0 https://github.com/Strident/Container

Simple dependency injection container, inspired by Pimple.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

dic