lion/dependency-injection

Container for dependency injection with DI-PHP

v4.5.0 2025-04-01 22:34 UTC

This package is auto-updated.

Last update: 2025-04-01 22:34:44 UTC


README

Lion-Packages Logo

Latest Stable Version Total Downloads License PHP Version Require

🚀 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.