2017 © Pedro Peláez
 

library container

Simple Lightweight container

image

kittenphp/container

Simple Lightweight container

  • Thursday, January 18, 2018
  • by kittenphp
  • Repository
  • 0 Watchers
  • 0 Stars
  • 25 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Introduced

This package is a lightweight service container., (*1)

install

composer require kittenphp/container, (*2)

Example

1. Define the service

Each service is an ordinary PHP class that can provide some functionality:, (*3)

class Service{
    public function show(){
        echo 'hello world! (kittenphp/container)';
    }
}

2. Registration service

use kitten\component\container\Container;
$c=new Container();
$c->set(Service::class,function (){
    return new Service();
});

3.Registering Shared Services

$c->share(Service::class,function (){
   return new Service();
});

4. Registering multiple services

class ServiceProvider implements ServiceProviderInterface{

    function register(ExpandContainerInterface $container)
    {
        $container->share(ServiceA::class,function (){
            return new ServiceA();
        });
        $container->share(ServiceB::class,function (){
            return new ServiceB();
        });
        $container->share(ServiceC::class,function (){
            return new ServiceC();
        });
    }
}
$c->addServiceProvider(new ServiceProvider());

5. Get Service

$c->get(Service::class)->show();

The Versions

18/01 2018

dev-master

9999999-dev

Simple Lightweight container

  Sources   Download

MIT

The Requires

 

by Avatar kittenphp

18/01 2018

1.0.0

1.0.0.0

Simple Lightweight container

  Sources   Download

MIT

The Requires

 

by Avatar kittenphp