PHP code example of systream / dependency-injection-container
1. Go to this page and download the library: Download systream/dependency-injection-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/ */
systream / dependency-injection-container example snippets
$di = new DependencyInjectionContainer();
$di->bind(FixtureTestInterface::class, function () {
return new ObjectA();
});
$di->has(FixtureTestInterface::class); // will return true
$instance = $di->get(FixtureTestInterface::class); // will return ObjectA instance
class TestObjectB {
public function __construct(FixtureTestInterface $test) {
}
}
$di = new DependencyInjectionContainer();
$di->bind(FixtureTestInterface::class, function () {
return new ObjectA();
});
$testObject = $di->create(TestObjectB::class);