PHP code example of gr8abbasi / php-di-container

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

    

gr8abbasi / php-di-container example snippets


use Mcustiel\Config\Drivers\Reader\php\Reader as PhpReader;
use Mcustiel\Config\Drivers\Reader\ini\Reader as IniReader;
use Mcustiel\Config\Drivers\Reader\json\Reader as JsonReader;
use Mcustiel\Config\Drivers\Reader\yaml\Reader as YamlReader;



return [
    'class-a'         => [
        'class'       => 'Tests\\DummyServices\\ClassA',
    ],
    'class-b'         => [
        'class'       => 'Tests\\DummyServices\\ClassB',
        'arguments'   => [
            'class-a'
        ]
    ],
    'class-c'         => [
        'class'       => 'Tests\\DummyServices\\ClassC',
        'arguments'   => [
            'class-b'
        ]
    ],
];

$loader = new ServiceLoader();

$services = $loader->loadServices(
    __DIR__ . "/Fixtures/phpServicesConfig.php",
    new PhpReader()
    );

$container = new Container($services);

// To get services from container
$service = $container->get('foo');



$services = $loader->loadServices(
    __DIR__ . "/Fixtures/jsonServicesConfig.json",
    new JsonReader()
    );



$services = $loader->loadServices(
    __DIR__ . "/Fixtures/yamlServicesConfig.yml",
    new YamlReader()
    );



$services = $loader->loadServices(
    __DIR__ . "/Fixtures/iniServicesConfig.ini",
    new IniReader()
    );