mouf/pimple-interop 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mouf/pimple-interop

Composer 安装命令:

composer require mouf/pimple-interop

包简介

This project is a very simple extension to the Pimple microframework. It adds to Pimple compatibility with the container-interop APIs.

README 文档

README

Latest Stable Version Latest Unstable Version License SensioLabsInsight

This package contains an extension to the Pimple DI container that makes Pimple 1 compatible with the container-interop API.

How to use it?

Instead of using the Pimple class, you can use the PimpleInterop class. This class extends Pimple. PimpleInterop implements ContainerInterface. This means you can access your Pimple entries by using the get and has methods. PimpleInterop constructor accepts an optional "root" container as a first argument. This means you can chain PimpleInterop with another container. Dependencies will be fetched from the "root" container rather than from PimpleInterop.

Here is a sample chaining 2 Pimple instances (in the real world, you would rather chain Pimple with a composite container than contains all the DI containers you are working with):

// Let's declare a first container
$pimpleParent = new PimpleInterop();
$pimpleParent['hello'] = 'world';

// Let's declare another container
// Please note the "parent" container is passed in parameter of the constructor.
$pimple = new PimpleInterop($pimpleParent);
$pimple['test']->share(function(ContainerInterop $container) {
	return "Hello ".$container->get('hello');
});

// Prints "Hello world".
echo $pimple->get('test');
// Prints "Hello world" too.
echo $pimple['test'];

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...)

But can't we already do this using Acclimate?

The excellent Acclimate library can already provide an adapter around Pimple. The adapter implements the ContainerInterface.

However, the adapter design pattern cannot be used to have Pimple delegate its dependencies fetching to another container. Indeed, to implement this feature, you need to modify the very behaviour of the container, and the adapter design pattern is not always well suited for this.

Also, there are other cases where the adapter design pattern is not enough. For instance, the Silex MVC microframework is directly extending the Pimple class. We could fork the Silex MVC microframework to make it use PimpleInterop instead of Pimple easily. However, it would be almost impossible for Silex to use the adapted Pimple instance from Acclimate (because Silex relies on all the methods of Pimple that are not implemented by the adapter).

mouf/pimple-interop 适用场景与选型建议

mouf/pimple-interop 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.46M 次下载、GitHub Stars 达 10, 最近一次更新时间为 2014 年 08 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「dependency injection」 「di」 「pimple」 「container-interop」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mouf/pimple-interop 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mouf/pimple-interop 我们能提供哪些服务?
定制开发 / 二次开发

基于 mouf/pimple-interop 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.46M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 36
  • 依赖项目数: 2
  • 推荐数: 2

GitHub 信息

  • Stars: 10
  • Watchers: 1
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-08-24