mouf/picotainer
Composer 安装命令:
composer require mouf/picotainer
包简介
This package contains a really minimalist dependency injection container compatible with container-interop.
README 文档
README
This package contains a really minimalist dependency injection container (24 lines of code!) compatible with container-interop (supports ContainerInterface and delegate lookup feature). It is also, therefore, compatible with PSR-11, the FIG container standard.
Picotainer is heavily influenced by the Pimple DI container. Think about it as a Pimple container with even less features, and ContainerInterop compatibility.
Installation
Before using Picotainer in your project, add it to your composer.json file:
$ ./composer.phar require mouf/picotainer ~1.0
Storing entries in the container
Creating a container is a matter of creating a Picotainer instance.
The Picotainer class takes 2 parameters:
- the list of entries, as an array of anonymous functions
- an optional delegate-lookup container
use Mouf\Picotainer\Picotainer; use Psr\Container\ContainerInterface; $container = new Picotainer([ "myInstance"=>function(ContainerInterface $container) { return new MyInstance(); }, "myOtherInstance"=>function(ContainerInterface $container) { return new MyOtherInstance($container->get('myInstance')); } "myParameter"=>function(ContainerInterface $container) { return MY_CONSTANT; } ], $rootContainer);
The list of entries is an associative array.
- The key is the name of the entry in the container
- The value is an anonymous function that will return the entry
The entry can be anything (an object, a scalar value, a resource, etc...)
The anonymous function must accept one parameter: the container on which dependencies will be fetched. The container is the "delegate-lookup container" if it was passed as the second argument of the constructor, or the Picotainer instance itself if no delegate lookup container was passed.
Fetching entries from the container
Fetching entries from the container is as simple as calling the get method:
$myInstance = $container->get('myInstance');
Why the need for this package?
This package is part of a long-term effort to bring interoperability between DI containers. The ultimate goal is to make sure that multiple containers can communicate together by sharing entries (one container might use an entry from another container, etc...)
mouf/picotainer 适用场景与选型建议
mouf/picotainer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 191.03k 次下载、GitHub Stars 达 16, 最近一次更新时间为 2015 年 01 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「dependency injection」 「di」 「container-interop」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mouf/picotainer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mouf/picotainer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mouf/picotainer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A fast and intuitive dependency injection container.
Symfony compiler pass that allows to use service providers as defined in container-interop/service-provider
Dependency injection container for the Monolith framework.
Http Microframework for Hack
PHP Dependency Injection Container
统计信息
- 总下载量: 191.03k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 16
- 点击次数: 18
- 依赖项目数: 15
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-01-21