cloudevents / sdk-php
CloudEvents SDK
v1.1.0
2023-12-18 02:56 UTC
Requires
- php: ^7.4.15 || ^8.0.2
- ext-json: *
- ext-pcre: *
- symfony/polyfill-php80: ^1.26
Requires (Dev)
- guzzlehttp/psr7: ^2.4.3
- php-http/discovery: ^1.15.2
- phpunit/phpunit: ^9.6.3 || ^10.0.12
- psalm/phar: 5.7.6
- psr/http-factory: ^1.0.1
- psr/http-message: ^1.0.1
- squizlabs/php_codesniffer: 3.7.2
Suggests
- php-http/discovery: Required for automatic discovery of HTTP message factories in the HTTP Marshaller.
- psr/http-factory: Required for use of the HTTP Marshaller.
- psr/http-factory-implementation: Required for use of the HTTP Marshaller.
- psr/http-message: Required for use of the HTTP Marshaller and Unmarshaller.
- psr/http-message-implementation: Required for use of the HTTP Marshaller and Unmarshaller.
README
状态
此SDK目前支持以下版本的CloudEvents
安装
使用 Composer 安装SDK
$ composer require cloudevents/sdk-php
创建CloudEvent
use CloudEvents\V1\CloudEvent; use CloudEvents\V1\CloudEventImmutable; // Immutable CloudEvent $immutableEvent = new CloudEventImmutable( '1n6bFxDMHZFChlI4TVI9tdzphB9', '/examples/php-sdk', 'com.example.type', ['example' => 'first-event'], 'application/json' ); // Mutable CloudEvent $mutableEvent = new CloudEvent( '1n6bFxDMHZFChlI4TVI9tdzphB9', '/examples/php-sdk', 'com.example.type', ['example' => 'first-event'], 'application/json' ); // Create immutable from mutable or via versa $event = CloudEventImmutable::createFromInterface($mutableEvent); $event = CloudEvent::createFromInterface($immutableEvent);
序列化/反序列化CloudEvent
use CloudEvents\Serializers\JsonDeserializer; use CloudEvents\Serializers\JsonSerializer; // JSON serialization $payload = JsonSerializer::create()->serializeStructured($event); $payload = JsonSerializer::create()->serializeBatch($events); // JSON deserialization $event = JsonDeserializer::create()->deserializeStructured($payload); $events = JsonDeserializer::create()->deserializeBatch($payload);
打包/解包CloudEvent
use CloudEvents\Http\Marshaller; use CloudEvents\Http\Unmarshaller; // Marshal HTTP request $request = Marshaller::createJsonMarshaller()->marshalStructuredRequest($event); $request = Marshaller::createJsonMarshaller()->marshalBinaryRequest($event); $request = Marshaller::createJsonMarshaller()->marshalBatchRequest($events); // Marshal HTTP response $request = Marshaller::createJsonMarshaller()->marshalStructuredResponse($event); $request = Marshaller::createJsonMarshaller()->marshalBinaryResponse($event); $request = Marshaller::createJsonMarshaller()->marshalBatchResponse($events); // Unmarshal HTTP message $events = Unmarshaller::createJsonUnmarshaller()->unmarshal($message);
测试
当贡献时,您可以使用 composer
来构建和运行测试环境。
$ composer run -l
scripts:
lint Show all current linting errors according to PSR12
lint-fix Show and fix all current linting errors according to PSR12
sa Run the static analyzer
tests Run all tests locally
tests-build Build containers to test against supported PHP versions
tests-docker Run tests within supported PHP version containers
社区
- 在每周二的美国太平洋时间上午9点(无服务器/CloudEvents会议之后),将立即举行双周会议。这意味着它们通常在上午10点开始,但如果其他会议提前结束,那么SDK会议也将提前开始。请参阅CloudEvents会议纪要以确定哪一周将举行会议。
- Slack: 在 CNCF的Slack工作区 下的 #cloudeventssdk 频道。
- 电子邮件: https://lists.cncf.io/g/cncf-cloudevents-sdk
- 如需更多信息,请联系Denis Makogon(在Slack上为
@denysmakogon
)。
每个SDK可能都有自己的独特流程、工具和指南,常见的治理相关材料可以在CloudEvents community
目录中找到。特别是,在那里您将找到有关如何管理SDK项目的信息管理,指南以及我们的行为准则信息。
如果您对CloudEvents规范或项目SDK中存在安全担忧,请将电子邮件发送至cncf-cloudevents-security@lists.cncf.io。