scabbiafw/scabbia2-services

该包已被 放弃 并不再维护。作者建议使用 eserozvataf/scabbia2-services 包。

Scabbia2 服务组件

v0.1.2 2015-09-16 02:37 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:51:18 UTC


README

此组件 是一个小型依赖项管理容器实现,允许您轻松共享、生成和访问实例/变量。

Build Status Scrutinizer Code Quality Total Downloads Latest Stable Version Latest Unstable Version Documentation Status

用法

基本键/值容器

use Scabbia\Services;

$container = new Services();

$container['key'] = 'value';

echo $container['key'];

单例访问

use Scabbia\Services;

$container = Services::getCurrent();

$container['key'] = ['sample', 'array'];

var_dump($container['key']);

设置工厂

use Scabbia\Services;

$container = Services::getCurrent();

$container->setFactory('key', function () {
    return ['time' => microtime(true)];
});

var_dump($container['key']);
var_dump($container['key']); // will be different than previous one

装饰

use Scabbia\Services;

$container = Services::getCurrent();

$container['key'] = 'test';

$container->decorate('key', function ($value) {
    return $value . 'ing';
});

$container->decorate('key', function ($value) {
    return strtoupper($value);
});

var_dump($container['key']); // returns 'TESTING'

链接

贡献

对任何贡献都公开。欢迎修复错误、新功能和额外模块。所有贡献应提交到 eserozvataf/scabbia2-services 仓库。

  • 要贡献代码:Fork 仓库,将您的更改推送到您的分叉,并提交一个 pull 请求。
  • 要报告错误:如果有什么东西不起作用,请使用 GitHub 问题报告。
  • 要支持:Donate