lion / dependency-injection
Container for dependency injection with DI-PHP
Installs: 2 593
Dependents: 2
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
Requires
- php: >=8.4
- php-di/php-di: ^7.0
Requires (Dev)
- infection/infection: ^0.29.14
- lion/test: ^2.1 || ^3.0
- overtrue/phplint: ^9.5
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.0
- squizlabs/php_codesniffer: ^3.11
README
🚀 Lion-DependencyInjection Container for dependency injection with DI-PHP.
📖 Features
✔️ Resolves a class or dependency from the container.
✔️ Calls a method on an object with automatic dependency injection.
✔️ Executes a callback with automatic dependency injection.
📦 Installation
Install the dependency-injection using Composer:
composer require lion/dependency-injection
Usage Example #1
<?php declare(strict_types=1); require_once('./vendor/autoload.php'); use App\Http\Controllers\UsersController; use Lion\Dependency\Injection\Container; $container = new Container(); /** @var UsersController $usersController */ $usersController = $container->resolve(UsersController::class); $response = $container->callMethod($usersController, 'createUsers'); var_dump($response);
Usage Example #2
<?php declare(strict_types=1); require_once('./vendor/autoload.php'); use App\Http\Controllers\UsersController; use Lion\Dependency\Injection\Container; $response = (new Container()) ->callCallback(function (UsersController $usersController) { return $usersController->createUsers(); }); var_dump($response);
📝 License
The dependency-injection is open-sourced software licensed under the MIT License.