usmanhalalit/viocon
Composer 安装命令:
composer require usmanhalalit/viocon
包简介
A simple and flexible Dependency Injection container for PHP.
关键字:
README 文档
README
A simple and flexible Dependency Injection or Service container for PHP.
It can be extremely helpful to decouple your dependencies. You can also mock dependencies at runtime.
Installation
Viocon uses Composer to make things easy.
Learn to use composer and add this to require (in your composer.json):
"usmanhalalit/viocon": "1.0.*@dev"
Library on Packagist.
Usage
$container = new \Viocon\Container();
You can optionally create a class alias too
new \Viocon\Container('Container');
Viocon will create a class alias for you with the given name 'Container'. Now you can use this class' methods statically, like
\Container::set(...); \Container::build(...);
And so ...
Bind a closure
$container->set('myClosure', function ($test1, $test2) { $stdClass = new \stdClass(); $stdClass->testVar1 = $test1; $stdClass->testVar2 = $test2; $stdClass->testMethod = function ($test3) { return $test3; }; return $stdClass; }); $object = $container->build('myClosure', array('Test Var 1', 'Test Var 2')) echo $object->testVar1;
Build Any Class and Optionally Pass Parameters
$container->build('\PDO', array('myConnectionInfo'));
Singleton
$container->set('mySingleton', '\\stdClass'); $stdClass = $container->build('mySingleton');
Replacing Objects at Runtime
It can be useful while testing with mocked object
$mockedClass = new \stdClass(); $mockedClass->testVar = 'mocked'; static::$container->setInstance('\\stdClass', $mockedClass); $stdClass = static::$container->build('\\stdClass'); $this->assertEquals('mocked', $stdClass->testVar);
usmanhalalit/viocon 适用场景与选型建议
usmanhalalit/viocon 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.35M 次下载、GitHub Stars 达 4, 最近一次更新时间为 2013 年 06 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「container」 「test」 「di」 「ioc」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 usmanhalalit/viocon 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 usmanhalalit/viocon 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 usmanhalalit/viocon 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Testing Suite For Lumen like Laravel does.
A fast and intuitive dependency injection container.
Specification-oriented BDD helpers for PHPUnit
Common IoC Api Interface
KissTest is command-line free, fast, simple and beautiful unit test framework.
Dependency injection container for the Monolith framework.
统计信息
- 总下载量: 2.35M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 37
- 依赖项目数: 10
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-06-24