2017 © Pedro Peláez
 

library service-container

A simple service container.

image

herrera-io/service-container

A simple service container.

  • Wednesday, February 20, 2013
  • by kherge
  • Repository
  • 2 Watchers
  • 4 Stars
  • 718 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 3 Versions
  • 1 % Grown

The README.md

Service Container

Build Status, (*1)

A simple service container., (*2)

Summary

This library provides a simple service container. It is heavily influenced by Fabien Potencier's Pimple project (in particular, Igor Wielder's modifications). The differences from Pimple are, (*3)

  • naming convention
  • handling of service provider registration
  • library specific exceptions
  • different implementations of shared() and protect()

Installation

Add it to your list of Composer dependencies:, (*4)

$ composer require herrera-io/service-container=1.*

Usage

Simple usage

<?php

use Herrera\Service\Container;

$container = new Container(array('var' => 123));

$container['factory'] = $container->many(function () {
    return new ArrayObject(array('rand' => rand()));
});

$container['shared'] = $container->once(function() {
    return new ArrayObject(array('rand' => rand()));
});

echo $container['factory']['rand']; // echo "1197692050"
echo $container['factory']['rand']; // echo "995449132"
echo $container['shared']['rand']; // echo "89432412"
echo $container['shared']['rand']; // echo "89432412"

Service provider usage

<?php

use Herrera\Service\Container;
use Herrera\Service\ProviderInterface;

class MyProvider implements ProviderInterface
{
    public function register(Container $container)
    {
        $container['hello'] = $container->once(function (Container $container) {
            echo 'Hello, ', $container['name'], "!\n";
        });
    }
}

$container =  new Container();
$container->register(new MyProvider(), array(
    'name' => 'Guest'
));

The Versions

20/02 2013

dev-master

9999999-dev http://herrera-io.github.com/php-service-container

A simple service container.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

service container dependency

31/01 2013

1.1.0

1.1.0.0 https://herrera-io.github.com/php-service-container

A simple service container.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

service container dependency

26/01 2013

1.0.0

1.0.0.0 https://herrera-io.github.com/php-service-container

A simple service container.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

service container dependency