定制 celemas/container 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

celemas/container

最新稳定版本:0.4.0

Composer 安装命令:

composer require celemas/container

包简介

A PSR-11 compatible dependency injection library

README 文档

README

ci codecov psalm coverage psalm level Software License

A PSR-11 compatible dependency injection container.

Entry lifetimes

Container entries use explicit lifetimes:

  • shared() caches one instance per container (default for added entries)
  • scoped() caches one instance per requesting container scope
  • transient() never caches
  • value() returns the configured definition as-is (for literals or raw closures)
$container->add('config', ['debug' => true])->value();
$container->add(Service::class)->shared();
$container->add(RequestContext::class)->scoped();
$container->add(Builder::class)->transient();

Scope mode

Use scope() to create an isolated container for one unit of work:

$root = new Container();
$root->add('app-name', 'celemas')->value();
$root->add('global-service', GlobalService::class)->shared();
$root->add('request-service', RequestService::class)->scoped();

$scope = $root->scope();
$scope->add(Request::class, $request)->value();

// ... resolve request-local services
$scope->reset();

After the first scope() call, the root container is sealed and no longer accepts structural mutations. Scope tags can inherit pre-defined root tags while keeping their own local caches.

Services that should be cleaned between scopes can implement Celemas\Container\Resettable and will be reset during $scope->reset().

License

This project is licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固