issei-m/sf-dependency-injection-plugin
Composer 安装命令:
composer require issei-m/sf-dependency-injection-plugin
包简介
Supporing Symfony's DependencyInjection component for your symfony1 project
README 文档
README
Provides integration Symfony2's Dependency Injection component with your older symfony (1.4+) project.
Installation
Using Composer would be best way:
$ composer require issei-m/sf-dependency-injection-plugin
Here, Composer would install this plugin in your plugins directory and some other libraries plugin depends on into vendor.
If you don't use Composer, you need to install this plugin and some others manually.
Usage
First, create your services.yml in %SF_ROOT%/config/services.yml. It can be defined your parameters/services to each different environments.
Something like:
# config/services.yml dev: parameters: mailer.transport: gmail all: parameters: # ... mailer.transport: sendmail services: mailer: class: Mailer arguments: ["%mailer.transport%"] newsletter_manager: class: NewsletterManager calls: - [setMailer, ["@mailer"]]
The services.yml is supporting the configuratoin cascade like the settings.yml, and it can be located in several different config directory for apps (e.g.apps/frontend/config).
When the ServiceContainer is compiled, the values from these are merged.
Next, enable this plugin at your ProjectConfiguration:
class ProjectConfiguration extends sfProjectConfiguration { public function setup() { $this->enablePlugins('sfDependencyInjectionPlugin'); ... } }
Now, your sfContext has installed Symfony's service container, it is used as following in your code:
// Get the ServiceContainer. $container = sfContext::getInstance()->getContainer(); // Retrieve the NewsletterManager class which was initialized with the Mailer. $newsletterManager = $container->get('newsletter_manager');
If you use lexpress/symfony1, sfServiceContainer is replaced with plugin's service container. But it might work almost as well as framework's one:
$container = sfContext::getInstance()->getServiceContainer(); $newsletterManager = sfContext::getInstance()->getService('newsletter_manager');
At task
Even though you don't initialize the sfContext at task, you can initialize the service container manually like this:
$containerClass = require $this->configuration->getConfigCache()->checkConfig('config/services.yml', true); $container = new $containerClass();
Event
When container is compiled, service_container.build event is fired. You can expand container definitions if you subscribe this event.
It means you can have control your service container as you wish with your own extension, compiler pass etc...:
class ProjectConfiguration extends sfProjectConfiguration { public function setup() { $this->dispatcher->connect('service_container.build', function (sfEvent $event) { /** @var \Symfony\Component\DependencyInjection\ContainerBuilder $container */ $container = $event->getSubject(); $container->addObjectResource($this); // additional parameter $container->setParameter('foo', 'bar'); // add extension $container->registerExtension(new YourExtension()); // add compiler pass $container->addCompilerPass(new YourPass()); }); } }
issei-m/sf-dependency-injection-plugin 适用场景与选型建议
issei-m/sf-dependency-injection-plugin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.53k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2013 年 10 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「plugin」 「service」 「dependency-injection」 「symfony1」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 issei-m/sf-dependency-injection-plugin 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 issei-m/sf-dependency-injection-plugin 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 issei-m/sf-dependency-injection-plugin 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
CakePHP 4.x AdminLTE Theme.
A fast and intuitive dependency injection container.
Registry service.
swagger-php - Generate interactive documentation for your RESTful API using phpdoc annotations
Powerful class discovery system for Laravel with attribute-based scanning, directory traversal, and monorepo support
Service auto install for Nette Framework
统计信息
- 总下载量: 11.53k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-10-19