A psr-11 container library

A psr-11 container library

README

Build Status
Coverage Status
SensioLabsInsight
Packagist
Packagist Pre Release
Packagist

ixocreate/servicemanager is a psr-11 container library built on top of zendframework/zend-servicemanager. Like
zend-servicemanager it is a factory based approach.

Installation

Install the package via composer:

composer require ixocreate/servicemanager

Testing

composer install --dev
phpunit

Usage

$configurator = new ServiceManagerConfigurator();
$configurator->addFactory(SomeObject::class);
$configurator->addFactory(AnotherObject::class, AnotherObjectFactory::class);
$configurator->addLazyService(SomeObject::class);
$serviceManager = new ServiceManager($configurator->getServiceManagerConfig(), new ServiceManagerSetup());

$serviceManager->get(SomeObject::class);
$serviceManager->build(AnotherObject::class);

Factories

A factory is any class that implements the interface IxocreateContractServiceManagerFactoryInterface.

class SomeObjectFactory implements FactoryInterface
{
    public function __invoke(ServiceManagerInterface $container, $requestedName, array $options = null)
    {
        return new SomeObject();
    }
}

$configurator = new ServiceManagerConfigurator();
$configurator->addFactory(SomeObject::class, SomeObjectFactory::class);
$serviceManager = new ServiceManager($configurator->getServiceManagerConfig(), new ServiceManagerSetup());

$serviceManager->get(SomeObject::class);

License

The MIT License (MIT). Please see LICENSE for more information.

Source

Add a Comment

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *