techdata/context-di-bundle
Composer 安装命令:
composer require techdata/context-di-bundle
包简介
Symfony2 library to allow for context aware services.
README 文档
README
Allows for context dependency injection.
Concept
The concept is that there is often the need to know the context of the request. A context can be made up of one or more different facets such as User, Customer, Domain, GeoLocation, User IP, The presence of an outstanding quote, etc
The bundle builds on the existing Symfony DI system by allowing custom providers and consumers to be defined and then tagghed with what the need or what they can provide.
The system does not load the context until it is needed.
There is cache so that the context is not recomputed everytime a service wants to use it.
Consumer
A consumer service must implement the TechData\ContextDiBundle\Interfaces\ContextConsumerInterface interface and then be tagged with one or more tags of name "context_consumer" which it wants to consume. The tag needs to have an attribute of "context_name" which is a string that specifies which type of context it is looking for.
Provider
A provider service must implement the TechData\ContextDiBundle\Interfaces\ContextProviderInterface interface and then be tagged with a single tag of name "context_provider" which it wants to provide. The tag needs to have an attribute of "context_name" which is a string that specifies which type of context being provided.
Cache
There is a cache which is checked prior to attempting to resolve the context. if the context is already available in the cache, it will be used. The default cache service caches the contexts per request.
Configuiration
The available types of context need to be specified (or "registered") in the main config file ("config.yml"). This is done by specifying the name of an interface or class which will be provided by the provider when the context is resolved. This ensures only certain contexts are available, and the context types are known to the consumer which will need to use them. Example.
tech_data_context_di:
available_contexts:
user: Vendor\Bundle\Interfaces\UserInterface
customer: Vendor\Bundle\Entity\CustomerInterface
Optionally, the cache type can be switched to a different cache service which implements the TechData\ContextDiBundle\Interfaces\ContextCacheInterface. This can be done by specifying the cache service name in the config as shown below. This defaults to "tech_data_context_di.cache.single_request" which is a per request cache.
tech_data_context_di:
available_contexts:
user: Vendor\Bundle\Interfaces\UserInterface
customer: Vendor\Bundle\Entity\CustomerInterface
cache_service: some.custom.cache.service.name
Included Providers
Some providers for common use cases will be added soon.
techdata/context-di-bundle 适用场景与选型建议
techdata/context-di-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 06 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「Context」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 techdata/context-di-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 techdata/context-di-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 techdata/context-di-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Behat Context for testing Symfony Api
Context support (request, session and application scope) for n2n framework.
The bundle for easy using json-rpc api on your project
Bundle Symfony DaplosBundle
Standalone CLI that generates codebase context (JSON + Markdown) for AI agents.
A library providing abstract implementations of various persistence layers based on JSON API relational resource concepts.
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-06-30