PHP code example of elverion / dependency-injection

1. Go to this page and download the library: Download elverion/dependency-injection 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/ */

    

elverion / dependency-injection example snippets




use Elverion\DependencyInjection\Container\Container;

class MyApp {
    private $client;

    public function __construct(Client $client) {
        $this->client = $client;
    }

    // ...
}

class Task {
    public function handle(MyApp $app) {
        // ...
    }
}



$container = Container::getInstance();

$task = new Task();
$container->call([$task, 'handle']); // Injects a Client into MyApp, then calls Task::handle() with the MyApp instance