Skip to content

A lightweight dependency injection tool, container based on the PSR-11 specification.

License

Notifications You must be signed in to change notification settings

next-laboratory/di

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

一款简单的容器,所有被容器实例化的类以及所有依赖都是单例

安装

环境要求 PHP >= 8.0

composer require next/di

使用

获取容器实例,注意不要直接实例化

$container = \Next\Di\Context::getContainer();
$container = container();

绑定类和别名,之后所有容器接口都可以使用TestInterface::class标识来获取Test::class实例

$container->bind(TestInterface::class, Test::class);

实例化

$container->make(Test::class);

获取对象

$container->get(Test::class);

调用方法

$conatiner->call(callable $callable, array $arguments = []);

注意:所有需要传参的api均需要关联数组,数组的键为参数的名字

About

A lightweight dependency injection tool, container based on the PSR-11 specification.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages