1. Go to this page and download the library: Download dc/ioc 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/ */
dc / ioc example snippets
$container = new \DC\IoC\Container();
$container
->register('\Car') // fully qualified namespace
->to('\IVehicle')
->withContainerLifetime(); // lives as long as the container
$container
->register(function() {
new \Car();
})->to('\IVehicle');
$vehicle = $container->resolve('\IVehicle');
$vehicles = $container->resolveAll('\IVehicle');
class Trailer {
public __construct(\IVehicle $vehicle) {
// attach your Trailer to you IVehicle, or something
}
}
$container->resolve("Trailer"); // you don't even have to register Trailer
class Trailer {
/**
* @param $matchesVehicles array|\IVehicle[]
*/
public __construct(array $matchesVehicles) {
}
}
class Trailer {
/**
* @param $matchesVehicles \IVehicle[]
*/
public __construct($matchesVehicles) {
}
}
class Car {
/**
* @inject
* @var \Trailer
*/
private $trailer;
}
$car = new Car();
$container->inject($car);
$container->register(function(\IFoo $foo) {
return new Bar($foo);
})->to('\Bar');