定制 dispify/weaver 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

dispify/weaver

Composer 安装命令:

composer require dispify/weaver

包简介

Simple Dependency Injection container with autoconfiguration and autowiring

README 文档

README

Build Status codecov GitHub license

Packagist PHP Version Support PSR-11 Support

Weaver

The simple Dependency Injection container with autoconfiguration and autowiring. Inspired by The DependencyInjection Component.

This library can help you to configure a lot of services for an example for a module test.

Getting started

Before using Weaver in your project, add it to your composer.json file:

$ composer require dispify/weaver

Usage

⚠️ When you register any service it is registered with specified class name neither implemented interfaces nor class aliases

⚠️ When the service has been instantiated Weaver overwrites all services which names are equals to the implemented interfaces, or the class aliases of the service with this instance of the service.

class A {}
class B {
    public function __construct(A $a) {}
}

$weaver = new \Dispify\Weaver\Weaver();
$weaver->weave(B::class, $arguments = []); // register dependency
$weaver->get(B::class); // instantiate and return object of B. The service of A is created via autowiring  

Features

Global shared parameters & Manual instantiated external services

The pre-defined parameters and the services can be provided manually. Any scalar value will be always registered as a named parameter.
Any object will be registered as a service with its class name, its parents class names, implemented interfaces and its declared class aliases (requires to include package "dispify/class_aliases")

Lazy instantiating

When you register any service you should provide a class name of the service and an array of the arguments of the constructor. The service will be instantiated only when this service will be requested by another service or an external caller.

The array of the arguments can be both an array of key-value and an indexed array.

Autoconfiguration

When service is requested to be instantiated the first action is determination of constructor's arguments via reflection. Weaver tries to resolve each argument with existent data such as arguments, services, shared parameters or default values.

Weaver uses next ways to resolve the determined argument:

  • Pick the argument by the name from the array of the arguments if it exists;
  • Pick the argument by the index from the array of the arguments if it exists;
  • Get the argument as a service if it is an object;
  • Pick the argument by the name from the shared parameters array if it exists;
  • Use a default value of the argument if it is specified;

The variadic argument is ignored by design. It will be able to change later.

Autowiring

When Weaver is resolving the argument which is an object it gets a service with a class name of the argument.

If the service is not registered than Weaver tries to register this service with the class name.

⚠️ If the class name does not exist or there is an interface is specified than the exception will be thrown.

Next Weaver is instantiating this service via the workflow of the lazy instantiating.

PSR-11 compatibility

Weaver is compatible with PSR-11, so you can pass any string as an identifier of the service when you are getting or checking existence the service. But you cannot register the service with a random string as the identifier. The class name or interface is allowed.

dispify/weaver 适用场景与选型建议

dispify/weaver 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 08 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 dispify/weaver 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-08-30