ultra-lite/container
Composer 安装命令:
composer require ultra-lite/container
包简介
README 文档
README
Ultra-Lite Container
An ultra-lightweight DI container. The Ultra-Lite container is PSR-11 compliant. (Previous versions supported container-interop instead.)
Use anonymous functions as factories to specify your services.
This container also supports the Delegate Lookup pattern, and comes with a basic composite container.
Usage
Setting services individually
$container->set( 'service-id', function (\Psr\Container\ContainerInterface $container) { return new \stdClass(); } );
Setting services from a config file
Add factory closures to the container inline, or using a config file as below.
Example config file:
return [ 'service-id' => function (\Psr\Container\ContainerInterface $container) { return new \stdClass(); }, ];
Using config file:
$container->configureFromFile('/wherever/config/di.php');
Service retrieval
Get services out of the container like this:
$object = $container->get('service-id');
See if a service exists
Check if something is in the container like this:
$thingExists = $container->has('service-id');
Use with the Delegate Lookup pattern
If you're not using the Delegate Lookup concept from the Container-Interop standard, ignore this bit. If you are, you can do this:
$container = new \UltraLite\Container\Container(); $delegateContainer = new \UltraLite\CompositeContainer\CompositeContainer(); // or any delegate container $compositeContainer->addContainer($container); // will vary for other composite containers $container->setDelegateContainer($myCompositeContainer);
The Ultra-Lite Composite Container is an extremely lightweight delegate container you may wish to use.
When the container is asked for a service using get(), it will return it. It will pass the Composite Container
into the factory closure, so it is from here that any dependencies of your service will be retrieved.
Alternatives
Ultra-Lite Container was originally inspired by Pimple, which still makes an excellent DI container in PHP. Container-Interop compliant wrappers are available. Another excellent project, Picotainer, is along similar lines, with the principle difference being that the dependencies are defined at the time of instantiation of the container.
Installation
composer require ultra-lite/container
Contributions
Contributions welcome.
You can run the tests with ./vendor/bin/behat -c tests/behat/behat.yml and ./vendor/bin/phpspec r -c tests/phpspec/phpspec.yml.
ultra-lite/container 适用场景与选型建议
ultra-lite/container 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19.39k 次下载、GitHub Stars 达 21, 最近一次更新时间为 2015 年 12 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ultra-lite/container 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ultra-lite/container 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 19.39k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 21
- 点击次数: 21
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-12-15