1. Go to this page and download the library: Download earc/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/ */
earc / di example snippets
use eArc\DI\DI;
DI::init();
di_get(SomeClass::class); // returns an instance of SomeClass::class
di_param('some.parameter'); // returns the value of the parameter `some.parameter`
class alphaCentauri {
//...
public function construct()
{
$this->dependency1 = di_get(DependencyOne::class);
$this->dependency2 = di_get(DependencyTwo::class);
$this->parameterAlpha = di_param('alpha');
$this->parameterBeta = di_param('beta');
$this->parameterGamma = di_param('gamma');
}
//...
}
class Example
{
public function getResult($param)
{
$math = di_get(Math::class);
return $math->calculate($param, di_param('pi'));
}
}
function depending_on_injection($param)
{
$math = di_get(Math::class);
return $math->calculate($param, di_param('pi'));
}
$result = depending_on_injection(42);
foreach (di_get_tagged('tag.name') as $handlerName => $argument) {
$handler = di_get($handlerName);
if ($handler->canHandleTask($task)) {
$result = $handler->handleTask($task);
return $result;
}
}
throw new TaskNotHandledException($task);
function something_cool($times) {
return $times.' x icecream';
}
di_static('something_cool')(42); // returns '42 x icecream'
function something_cool_but_its_winter($times) {
return $times.' x hot tea';
}
di_decorate('something_cool', 'something_cool_but_its_winter');
di_static('something_cool')(42); // returns '42 x hot tea'
$ PHP Fatal error: Uncaught Error: Maximum function nesting level of '256' reached, aborting!
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.