stephanecoinon/ioc-container

v0.1 2017-08-17 21:43 UTC

This package is auto-updated.

Last update: 2024-09-11 14:33:12 UTC


README

Codeship Status for stephanecoinon/ioc-container

多功能的IoC容器包,围绕其拉入的框架的容器。

当这个包被拉入一个框架(例如Laravel、Symfony...)时,它会自动检测并围绕框架的本地IoC容器进行包装。

在纯PHP环境中使用时,此包使用PHP League容器

这在开发一个需要IoC容器但还附带流行框架服务提供者的无框架包时非常有用。它提供了一个通用的IoC容器API,利用框架的本地IoC容器,而您的包永远不会直接拉入框架。

当前支持的框架有

要求

  • PHP 7

安装

composer require stephanecoinon/ioc-container

用法

<?php

use StephaneCoinon\Container\Container;

require 'vendor/autoload.php';

// Boot the container
// You should add this line in your bootstrap or application service provider
Container::boot();

// Store a key/value into the container
Container::add('foo', 'bar');

// Resolve a key out of the container
$bar = Container::get('foo');

// Check whether a key is stored in the container
if (Container::has('foo')) {
    echo 'Foo is in the container';
}

// Container instantiates a new instance if the key is an existing class that's
// not in the container yet
$object = Container::get('\My\Super\DuperClass');

// Get the native container instance
$nativeContainer = Container::getInstance();

许可证

此包是开源软件,根据MIT许可证授权。