sauber-php/container

用于 Sauber PHP 框架的容器组件

dev-main 2022-05-27 11:47 UTC

This package is not auto-updated.

Last update: 2024-09-14 21:38:07 UTC


README

容器

GitHub release (latest by date) Tests Static Analysis Total Downloads GitHub

这是 Sauber PHP 框架使用的 DI 容器仓库。

安装

通常不需要安装此包,因为它随 Sauber PHP 框架预装,但如果您想在外部框架中使用它,请使用 composer

composer require sauber-php/container

使用

要使用容器,您可以手动添加定义

$container = new Container(
    definitions: [
        UserRepositoryInterface::class => UserRepository::class,
    ],
);

$repository = $container->get(
    id: UserRepositoryInterface::class,
);

要创建一个新的容器,并注入可调用对象

$injectors = [
    UserRepositoryInterface::class => UserRepository::class,
];

$container = Container::make(
    injectors: $injectors,
);

$repository = $container->get(
    id: UserRepositoryInterface::class,
);

测试

要运行测试

./vendor/bin/pest

静态分析

要检查静态分析

./vendor/bin/phpstan analyse

变更日志

请参阅 变更日志 以获取有关最近更改的更多信息。