lwlwilliam/container
最新稳定版本:1.0.2
Composer 安装命令:
composer require lwlwilliam/container
包简介
Minimal PSR-11 Container
README 文档
README
Minimal PSF-11 Container
来源: https://ryangjchandler.co.uk/posts/build-your-own-service-container-in-php-minimal-container
使用
$ composer require psr11_container
<?php
// test.php
include 'vendor/autoload.php';
use Demo\Container;
try {
$container = new Container();
$object = new stdClass();
$object->name = 'hello world';
$container->bind('hello', $object);
print_r($container->get('hello'));
print_r($container->get('hello2'));
} catch (Throwable $e) {
print_r($e);
}
$ php test.php
stdClass Object
(
[name] => hello world
)
Demo\exceptions\ServiceNotFoundException Object
(
[message:protected] => hello2
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /Users/wu/www/github.com/lwlwilliam/test/php/container/src/Container.php
[line:protected] => 20
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => /Users/wu/www/github.com/lwlwilliam/test/php/container/examples/test.php
[line] => 15
[function] => get
[class] => Demo\Container
[type] => ->
[args] => Array
(
[0] => hello2
)
)
)
[previous:Exception:private] =>
)
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-06-27