mouf/alias-container 问题修复 & 功能扩展

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

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

mouf/alias-container

最新稳定版本:v2.0.0

Composer 安装命令:

composer require mouf/alias-container

包简介

This package contains a really minimalist dependency injection container that can be used to create aliases of instances in existing containers.

README 文档

README

Latest Stable Version Latest Unstable Version License Scrutinizer Code Quality SensioLabsInsight Build Status Coverage Status

This package contains a really minimalist dependency injection container that can be used to create aliases of instances in existing containers. Alias-container is compatible with container-interop and is meant to be used in conjunction with other containers. By itself, Alias-container does not store any entry. It can only be used to create aliases of instances stored in other containers.

You can use AliasContainer to add support for alias for any container that does not support this feature.

Installation

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

$ ./composer.phar require mouf/alias-container ~1.0

Defining aliases in the container

Creating an alias container is a matter of creating an AliasContainer instance. The AliasContainer class takes 2 parameters:

  • a delegate-lookup container (e.g. the container we will look aliases into)
  • the list of aliases, as an associative array of strings
use Mouf\AliasContainer;
use Interop\Container\ContainerInterface;

$aliasContainer = new AliasContainer($rootContainer, [
	"myAlias"=>"myInstance",
	"myAlias2"=>"myInstance2"
]);

The list of entries is an associative array.

  • The key is the identifier of the alias to create
  • The value is the identifier of the entry that will be aliased

Fetching entries from the container

Fetching entries from the container is as simple as calling the get method:

$myInstance = $aliasContainer->get('myAlias');

Adding aliases to the container

You can add new aliases using the set method.

$aliasContainer->set('newAlias', 'myInstance');
Note that it is more efficient to initialize aliases in the container than calling recursively the set method.

Removing aliases from the container

You can add new aliases using the remove method.

$aliasContainer->remove('myAlias');

Why the need for this package?

This package is part of a long-term effort to bring interoperability between DI containers. The ultimate goal is to make sure that multiple containers can communicate together by sharing entries (one container might use an entry from another container, etc...)

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 17
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-01-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固