PHP code example of ellipse / container

1. Go to this page and download the library: Download ellipse/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/ */

    

ellipse / container example snippets




namespace App;

use Interop\Container\ServiceProviderInterface;

class ServiceProviderA implements ServiceProviderInterface
{
    public function getFactories()
    {
        return [
            'id' => function ($container) {

                return 'abc';

            },
        ]
    }

    public function getExtensions()
    {
        return [
            //
        ]
    }
}



namespace App;

use Interop\Container\ServiceProviderInterface;

class ServiceProviderB implements ServiceProviderInterface
{
    public function getFactories()
    {
        return [
            //
        ]
    }

    public function getExtensions()
    {
        return [
            'id' => function ($container, string $previous) {

                return $previous . 'def';

            },
        ]
    }
}



namespace App;

use Ellipse\Container;

// Get a container with a list of service providers.
$container = new Container([
    new ServiceProviderA,
    new ServiceProviderB,
]);

// Return true.
$container->has('id');

// Return 'abcdef'.
$container->get('id');