castor/context

PHP 的上下文信息传递抽象

1.1.0 2022-10-28 11:05 UTC

This package is auto-updated.

Last update: 2024-09-28 15:06:38 UTC


README

php-workflow code-coverage

为现代 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

要了解这个库背后的原因、使用最佳实践和实现示例,请查看 文档