定制 pkerrigan/di 二次开发

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

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

pkerrigan/di

最新稳定版本:v2.0.1

Composer 安装命令:

composer require pkerrigan/di

包简介

A lightweight dependency injector

README 文档

README

Build Status Code Climate Coverage PHP 8.4 Packagist

pkerrigan/di

A simple, lightweight PHP 8.4 dependency injector.

Why?

This was for fun, and doesn't really compare to the features offered by the popular dependency injectors. If you just need to inject objects then you may find this useful.

Usage

$injector = Injector::getInstance();
 
$injector->addClassResolver(new ArrayMapClassResolver([
    Interface::class => ConcreteImplementation::class
]));
 
$instance = $injector->get(Interface::class);

By default, all objects are treated as lazy singletons (that is, the same object will be returned for successive calls to get()). If you wish an object to be constructed again for every call of get (or injection) then you can explicitly define it as a Prototype like so:

$injector->addClassResolver(new ArrayMapClassResolver([
    Interface::class => new Prototype(ConcreteImplementation::class)
]));

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2017-11-18