cheerios/cheerios-container 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

cheerios/cheerios-container

最新稳定版本:v1.0.0

Composer 安装命令:

composer require cheerios/cheerios-container

包简介

README 文档

README

This is a minimal and configurable implementation of a PHP dependency injection container.

Usage

Creating an instance of a class

Calling ->get() or invoking the container will yield an instance of the provided class name.

$container = Container::getInstance();

$instance = $container->get(SomeClass::class);
$otherInstance = $container(SomeClass::class); // __invoke() is a short-hand for get()

Setting default arguments and passing arguments to the Container

Default arguments can be set for classes that have primitive arguments in their constructors. Additionally, arguments can be passed to ->get() or __invoke() and they will override any conflicting pre-registered value. Trying to create an instance of a class with a primitive argument without providing a value will throw.

$container = Container::getInstance()
    ->registerArgs(SomeClass::class, [
        "argumentOne" => "hello",
        "argumentTwo" => "overwrite me!",
    ]);

$instance = $container(
    class: SomeClass::class,
    args: ["argumentTwo" => "world"]
);

Setting strategies

Strategies skip the Container's resolver entirely, as well as registered interfaces and arguments.

$container->registerStrategy(SpecialClass::class, function() {
    return specialFunctionThatReturnsASpecialClassInstance();
});

$specialInstance = $container(SpecialClass::class);

Registering a default for an interface

The provided class name is instantiated when the Container is called on its interface.

$container->registerInterface(SomeInterface::class, SomeClass::class);

$instance = $container(SomeInterface::class);

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固