PHP code example of pedhot-dev / nepotismfree-di-autowire
1. Go to this page and download the library: Download pedhot-dev/nepotismfree-di-autowire 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/ */
pedhot-dev / nepotismfree-di-autowire example snippets
use PedhotDev\NepotismFree\Core\NepotismFree;
use PedhotDev\NepotismFree\Autowire\Autowire;
use PedhotDev\NepotismFree\Autowire\AutowireResolver;
// 1. Build your strict container (Definitions & Singletons)
$builder = NepotismFree::createBuilder();
$builder->bind(Database::class, fn() => new Database(...));
$container = $builder->build();
// 2. Wrap it with Autowire
$resolver = new AutowireResolver($container);
$autowire = new Autowire($resolver);
// 3. Resolve!
// 'UserController' is NOT in the container, but Autowire creates it
// and injects 'Database' from the strict container.
$controller = $autowire->resolve(UserController::class);