zap/injector 问题修复 & 功能扩展

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

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

zap/injector

Composer 安装命令:

composer require zap/injector

包简介

A simple Dependency Injector for PHP 5.4+

README 文档

README

Build Status

A simple dependency injection library

The Zap Injector looks to find the middle ground between the simplicity offered by tiny service locators like Pimple and the real dependency injection libraries like PHP-DI provide.

Why would I use this?

  • It handles resolving dependencies and their configuration in order.
  • It allows for dependencies to only be loaded on demand.
  • It allows configuration to only be loaded on demand, and to be configured from anywhere.
  • If you register under parent classes or interfaces, it decouples modules from their dependencies.

Usage:

$injector = new \iMarc\Zap\Injector();

// Register a factory under a class or interface name:
$injector->register('Request', function() {
	return new Request();
});

// Or Register a specific instance:
$injector->register(Request::createFromGlobals());

// Or register a class to simply be constructed:
$injector->register('Session');

// Invoke a callable, and Injector will fill in the dependencies:
$returnValue = $injector->invoke(function(Request $req, Session $sess) {
	return array($req, $sess);
});

// Similarly, construct an instance of a class with dependencies:
$instance = $injector->create('some\class');

Also, Injector has an extend method. Extensions are invoked immediately after a new instance is constructed from a factory or from a classname:

$injector->extend('Request', function(Request $req) {
	$req->setSomethingImportant(true);
});

Changelog

0.x

0.3.0

  • Major refactoring and code cleanup.

0.2.0

  • Added ->register(), removed ->addFactory(), ->addInstance(), and ->addClass()
  • Renamed ->remove() to ->unregister()
  • Other refactoring

0.1.1

  • Added ->extend() method, similar to Pimple. Callbacks configured with ->extend() are called after an instance is created by a factory.

0.1.0

  • Initial Release, full of bugs

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-03-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固