techdata/context-di-bundle 问题修复 & 功能扩展

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

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

techdata/context-di-bundle

最新稳定版本:1.0.0

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.

统计信息

  • 总下载量: 15
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-06-30