cloudevents/sdk-php
CloudEvents PHP SDK (v1.0) for creating mutable/immutable events, JSON serialize/deserialize, and HTTP marshal/unmarshal in structured, binary, and batch formats. Install via Composer and integrate CloudEvents into your PHP apps.
This SDK currently supports the following versions of CloudEvents:
Install the SDK using Composer:
composer require cloudevents/sdk-php
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);
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);
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);
You can use composer to build and run test environments when contributing.
$ 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
@denysmakogon on slack).Each SDK may have its own unique processes, tooling and guidelines, common
governance related material can be found in the
CloudEvents community
directory. In particular, in there you will find information concerning
how SDK projects are
managed,
guidelines
for how PR reviews and approval, and our
Code of Conduct
information.
If there is a security concern with one of the CloudEvents specifications, or with one of the project's SDKs, please send an email to cncf-cloudevents-security@lists.cncf.io.
How can I help you explore Laravel packages today?