2017 © Pedro Peláez
 

library container

Simple, configurable, service container.

image

phpbench/container

Simple, configurable, service container.

  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 6 Versions
  • 12 % Grown

The README.md

PHPBench Service Container

Build Status, (*1)

Simple, extensible dependency injection container with parameters and service tagging. Implements container interop., (*2)

Simple usage

$container = new Container();
$container->register('foobar', function (Container $container) {
    return new \stdClass();
});

Extending and Tagging

Extension classes should be passed as the first argument to the container (the user configuration is the second argumnet)., (*3)

$container = new Container(
    [
        MyExtension::class
    ],
    [
        'foo.bar' => 'my_new_value',
    ]
);
$container->init(); // will trigger loading of the extensions.
class MyExtension implements ExtensionInterface
{
    public function load(Container $container)
    {
        $container->register('my_service', function (Container $container) {
            $service = new MyService(
                $container->getParameter('foo_bar'),
                $container->get('some_other_service')
            );

            foreach ($container->getServiceIdsForTag('tag') as $serviceId => $params) {
                $service->add($container->get($serviceId));
            }

            return $service;
        });

        $container->register('tagged_service', function (Container $container) {
            return new MyService(
                $container->getParameter('foo_bar'),
                $container->get('some_other_service')
            );
        }, [ 'tag' => [ 'param1' => 'foobar' ]);
    }

    /**
     * Return the default parameters for the container.
     *
     * @return array
     */
    public function getDefaultConfig()
    {
        return [
            'foo_bar' => 'this is foo'
        ];
    }
}

The Versions

12/02 2018

dev-master

9999999-dev

Simple, configurable, service container.

  Sources   Download

MIT

The Requires

 

The Development Requires

12/02 2018

1.2

1.2.0.0

Simple, configurable, service container.

  Sources   Download

MIT

The Requires

 

The Development Requires

18/07 2017

1.1

1.1.0.0

Simple, configurable, service container.

  Sources   Download

MIT

The Requires

 

17/09 2016

1.0

1.0.0.0

Simple, configurable, service container.

  Sources   Download

MIT

The Requires

 

17/09 2016

dev-remove_build

dev-remove_build

Simple, configurable, service container.

  Sources   Download

MIT

The Requires

 

29/06 2016

dev-no_build

dev-no_build

Simple, configurable, service container.

  Sources   Download

MIT

The Requires