定制 rehmat/service-locator 二次开发

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

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

rehmat/service-locator

Composer 安装命令:

composer require rehmat/service-locator

包简介

A simple dependency injection library for php

README 文档

README

A simple and light weight Dependency Injection library for PHP projects.

##Requires composer autoloading

#How to use?

In your php code, make sure to require composer's autoload

require 'vendor/autoload.php';

You have to import the Rehmat\ServiceLocator\ServiceLocator namespace

use Rehmat\ServiceLocator\ServiceLocator;
//instantiate ServiceLocator
$serviceLocator = ServiceLocator::getInstance();

//add configuration through which ServiceLocator can locate the factory to create your desired classes
// the ::class is required for retrieving the Fully Qualified Class Name (FQCN)
$serviceLocator->register(MyClassInterface::class, MyClassFactory::class, 'prod' );

The first parameter is the class that we want to register, the second parameter is the factory that we want to use when locating our class, the third parameter is used as a mode, while retrieving our class, if same class is registered twice but under different mode, the mode we specify takes precedence.

$myClassObj = $serviceLocator->create(MyClassInterface::class, 'prod');

Or, you can use our config reader and do it in a much quicker way.

//change this line to use ConfigReader too
use Rehmat\ServiceLocator\{ServiceLocator, ConfigReader};

$configs = [
	'prod'	=> [
		MyClassInterface::class => MyClassFactory::class
	]
];

(new ConfigReader())->fromArray($configs);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2018-03-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固