cloudevents/sdk-php

CloudEvents SDK

v1.1.0 2023-12-18 02:56 UTC

This package is auto-updated.

Last update: 2024-09-18 04:51:06 UTC


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

其他SDK资源