PHP code example of lumax / dependency-injection-component
1. Go to this page and download the library: Download lumax/dependency-injection-component 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/ */
lumax / dependency-injection-component example snippets
use Luma\DependencyInjectionComponent\DependencyContainer;
// Create a container
$container = new DependencyContainer();
// Add a dependency
$container->add(MyDependency::class, new MyDependency());
// Retrieve a dependency
$dependency = $container->get(MyDependency::class);
use Luma\DependencyInjectionComponent\DependencyContainer;
use Luma\DependencyInjectionComponent\DependencyManager;
// Create a container
$container = new DependencyContainer();
// Create a manager and load dependencies from a YAML file
$manager = new DependencyManager($container);
$manager->loadDependenciesFromFile('path/to/dependencies.yaml');