PHP code example of kittenphp / container

1. Go to this page and download the library: Download kittenphp/container library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kittenphp / container example snippets


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

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

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

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());

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