PHP code example of gephart / dependency-injection
1. Go to this page and download the library: Download gephart/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/ */
gephart / dependency-injection example snippets
class A
{
public function hello(string $world): string
{
return "hello " . $world;
}
}
class B
{
private $a;
public function __construct(A $a)
{
$this->a = $a;
}
public function render()
{
return $this->a->hello("world");
}
}
$container = new \Gephart\DependencyInjection\Container();
$b = $container->get(B::class);
$b->render(); // hello world