herrera-io/service-container 问题修复 & 功能扩展

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

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

herrera-io/service-container

最新稳定版本:1.1.0

Composer 安装命令:

composer require herrera-io/service-container

包简介

A simple service container.

README 文档

README

Build Status

A simple service container.

Summary

This library provides a simple service container. It is heavily influenced by Fabien Potencier's Pimple project (in particular, Igor Wielder's modifications). The differences from Pimple are

  • naming convention
  • handling of service provider registration
  • library specific exceptions
  • different implementations of shared() and protect()

Installation

Add it to your list of Composer dependencies:

$ composer require herrera-io/service-container=1.*

Usage

Simple usage

<?php

use Herrera\Service\Container;

$container = new Container(array('var' => 123));

$container['factory'] = $container->many(function () {
    return new ArrayObject(array('rand' => rand()));
});

$container['shared'] = $container->once(function() {
    return new ArrayObject(array('rand' => rand()));
});

echo $container['factory']['rand']; // echo "1197692050"
echo $container['factory']['rand']; // echo "995449132"
echo $container['shared']['rand']; // echo "89432412"
echo $container['shared']['rand']; // echo "89432412"

Service provider usage

<?php

use Herrera\Service\Container;
use Herrera\Service\ProviderInterface;

class MyProvider implements ProviderInterface
{
    public function register(Container $container)
    {
        $container['hello'] = $container->once(function (Container $container) {
            echo 'Hello, ', $container['name'], "!\n";
        });
    }
}

$container =  new Container();
$container->register(new MyProvider(), array(
    'name' => 'Guest'
));

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-01-31