1. Go to this page and download the library: Download quillstack/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/ */
quillstack / di example snippets
use Quillstack\DI\Container;
final class ExampleController
{
public function __construct(private Database $database)
{
}
}
$controller = (new Container())->get(ExampleController::class);
// App\ExampleController, with its Database already there
use Psr\Log\LoggerInterface;
use Quillstack\Logger\Logger;
$logger = new Logger();
$container = new Container([
LoggerInterface::class => $logger,
]);
$container->get(LoggingController::class)->logger === $logger; // true
use Quillstack\DI\Container;
use Quillstack\DI\CustomFactoryInterface;
final class ReportFactory implements CustomFactoryInterface
{
private Container $container;
public function setContainer(Container $container): self
{
$this->container = $container;
return $this;
}
public function create(string $id): object
{
return new SalesReport($id);
}
}