PHP code example of guanguans / di
1. Go to this page and download the library: Download guanguans/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/ */
guanguans / di example snippets
php
creteStub{}
$container = new \Guanguans\Di\Container();
// Simple Bindings
$container->bind(ConcreteStub::class, function ($container) {
return new ConcreteStub();
});
// Binding A Singleton
$container->singleton('ConcreteStub', function ($container) {
return new ConcreteStub();
});
// Binding Interfaces To Implementations
$container->bind(
'App\Contracts\EventPusher',
'App\Services\RedisEventPusher'
);
// Resolving
$concreteStub = $container->make(ConcreteStub::class);