1. Go to this page and download the library: Download iquxbyte/container-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/ */
use IquxByte\ContainerDI;
Simple bind class to container
*/
ContainerDI::bind(Foo::class);
/**
* bind with custom name
*/
ContainerDI::bind('class.foo', Foo::class);
/**
* use closure to bind
*/
ContainerDI::bind(Foo::class, function ($containerDI) {
return new Foo;
});
/**
* bind class with interface to container
*/
ContainerDI::bind(FooBarContract::class, FooBar::class);
/**
* Get instance
*/
$instance = ContainerDI::make(FooBar::class);
/**
* Get class from interface
*/
$instance = ContainerDI::make(FooBarContract::class);
/**
* Singleton class to container
*/
ContainerDI::singleton(Bar::class);
/**
* Test singleton
* should be true
*/
var_dump(ContainerDI::make(Bar::class) === ContainerDI::make(Bar::class));
/**
* Test bind
* should be false
*/
var_dump(ContainerDI::make(FooBarContract::class) === ContainerDI::make(FooBarContract::class));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.