castor / context
PHP 的上下文信息传递抽象
1.1.0
2022-10-28 11:05 UTC
Requires
- php: >=8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.11
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^4.27
README
为现代 PHP 项目提供上下文信息传递抽象,灵感来源于 Golang 的 context
包。
安装
composer require castor/context
快速开始
<?php use Castor\Context; // This is a default base context $ctx = Context\nil(); // This returns a new context with the passed values stored $ctx = Context\withValue($ctx, 'foo', 'bar'); // Later in the call stack echo $ctx->value('foo'); // Prints: bar
要了解这个库背后的原因、使用最佳实践和实现示例,请查看 文档。