mouf/root-container
Composer 安装命令:
composer require mouf/root-container
包简介
This package contains a PHP DI container detector and aggregator. The idea is to have potentially one DI container per composer package and to aggregate all those containers into a 'root' container.
关键字:
README 文档
README
RootContainer is a facade for a composite container that aggregates all DI containers detected in the application.
The big picture
The ultimate goal is to allow the application developer to easily create a "root container", that can automatically detect and add containers contained in other packages into a global composite container that can be used by the application.
Compared to the classical way of thinking about a web application, this is a paradigm shift.
In a "classical" application, packages added to the application may add new instances to the main and only DI container. This is what SF2 bundles, ZF2 modules or Mouf2 packages are doing.
Using this approach, each package provides its own DI container that contains instances. DI containers are added to a global container that is queried.
About this package
Detection of other containers is done using the Container-Installer component.
This package is using detected packages and aggregate those into a unique composite container. This container is exposed as a facade.
So basically, using RootContainer, you can access ANY instance of ANY container of your application using:
$instance = RootContainer::get("instance_name");
In the background, RootContainer will load the containers.php file generated by
Container-Installer and instanciate all the containers
of the application.
A word of caution
Having an easy to use facade for containers does not allow you to use it all over the place :) Otherwise, you would be using the RootContainer as a service locator, which is considered by most people to be a bad practice (tip: the author of RootContainer thinks it is a bad practice too).
So in a perfect world, the RootContainer should be used once or twice in your application, maybe by the MVC framework you are using, to fetch the controller, and that's it.
That being said, it's always useful to be able to access an instance quickly for testing purposes.
mouf/root-container 适用场景与选型建议
mouf/root-container 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 302 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 01 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「di」 「ContainerInterop」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mouf/root-container 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mouf/root-container 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mouf/root-container 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
统计信息
- 总下载量: 302
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2015-01-16