项目作者: arikaim

项目描述 :
Dependency Injection Container
高级语言: PHP
项目地址: git://github.com/arikaim/container.git
创建时间: 2017-12-11T13:09:00Z
项目社区:https://github.com/arikaim/container

开源协议:MIT License

下载


Arikaim Container

version: 1.0.0
license: MIT

Mini Dependency Injection Container

PSR-11 compatibility

Installation

  1. composer require arikaim/container

Usage

  1. use Arikaim\Container\Container;
  2. $container = new Container();

Add service to container

  1. $container['service'] = function() {
  2. echo "Service example";
  3. };
  4. $container->add('service_add',function() {
  5. echo "Service add example";
  6. });
  7. $container->add('date',function () {
  8. return new \DateTime();
  9. });
  10. $date = $container['date'];
  11. echo $date->format('Y-m-d');

Add parameters

  1. $container['config'] = "Config value";

Replace service

  1. $container->replace('service',function() {
  2. echo "Replace Service";
  3. });

Psr-11 compatibility implement the PSR-11 ContainerInterface

  1. $servcie = $container->get('service');
  2. if ($container->has('service')) {
  3. \\ Service exists
  4. }

License

MIT License