progphil1337 / php-di
Simple but effective dependency injection library
Installs: 132
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/progphil1337/php-di
Requires
- php: ^8.1
README
Simple but effective dependency injection library
Installation
Install with composer:
$ composer require progphil1337/php-di
Compatibility
ProgPhil1337\DependencyInjection
requires PHP 8.1 (or better).
Usage
Basic example
ExampleForm.php
use ProgPhil1337\DependencyInjection\ClassLookup; use ProgPhil1337\DependencyInjection\Injector; use MyApp\YamlConfig; use MyApp\AbstractConfig; use MyApp\SingletonInterface; $lookup = new ClassLookup(); $injector = new Injector($lookup); $lookup // class aliases ->alias(YamlConfig::class, AbstractConfig::class) // register singletons ->singleton(SingletonInterface::class) // Register classes that cannot be created ->register(new YamlConfig()) ; // Example for alias and registering $yamlConfig = $injector->create(AbstractConfig::class);