PHP code example of elephox / di

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

    

elephox / di example snippets




use Elephox\DI\ServiceCollectionOld;

$container = new ServiceCollectionOld();
$container->addSingleton(stdClass::class, stdClass::class, fn () => new stdClass());

$foo = function (stdClass $object) {
    return $object;
}

$instance = $container->resolver()->call($foo);
// $instance is an instance of stdClass
// multiple calls to $container->resolver()->callback($foo) will return the same instance, since it was added as a singleton