椭圆形 / 容器
0.4.10
2018-03-19 16:32 UTC
Requires
- php: >=7.0
- container-interop/service-provider: ^0.4.0
- ellipse/type-errors: ^1.0
Requires (Dev)
- eloquent/phony-kahlan: ^1.0
- kahlan/kahlan: ^4.0
Provides
README
要求 php >= 7.0
安装 composer require ellipse/container
运行测试 ./vendor/bin/kahlan
入门指南
Ellipse\Container
类的构造函数接收一个 Interop\Container\ServiceProviderInterface
实现的数组。这是将服务提供者和服务定义注册到容器中的唯一方式。
如果传递给 Container
类构造函数的数组中的任何元素不是 ServiceProviderInterface
的实现,将抛出 Ellipse\Container\Exceptions\ServiceProviderTypeException
。
<?php namespace App; use Interop\Container\ServiceProviderInterface; class ServiceProviderA implements ServiceProviderInterface { public function getFactories() { return [ 'id' => function ($container) { return 'abc'; }, ] } public function getExtensions() { return [ // ] } }
<?php namespace App; use Interop\Container\ServiceProviderInterface; class ServiceProviderB implements ServiceProviderInterface { public function getFactories() { return [ // ] } public function getExtensions() { return [ 'id' => function ($container, string $previous) { return $previous . 'def'; }, ] } }
<?php namespace App; use Ellipse\Container; // Get a container with a list of service providers. $container = new Container([ new ServiceProviderA, new ServiceProviderB, ]); // Return true. $container->has('id'); // Return 'abcdef'. $container->get('id');