cloudevents / sdk-php
CloudEvents SDK
Installs: 2 310 572
Dependents: 4
Suggesters: 0
Security: 0
Stars: 80
Watchers: 15
Forks: 21
Open Issues: 1
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
Status
This SDK currently supports the following versions of CloudEvents:
Installation
Install the SDK using Composer:
$ composer require cloudevents/sdk-php
Create a 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);
Serialize/Deserialize a 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);
Marshal/Unmarshal a 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);
Testing
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
Community
- There are bi-weekly calls immediately following the Serverless/CloudEvents call at 9am PT (US Pacific). Which means they will typically start at 10am PT, but if the other call ends early then the SDK call will start early as well. See the CloudEvents meeting minutes to determine which week will have the call.
- Slack: #cloudeventssdk channel under CNCF's Slack workspace.
- Email: https://lists.cncf.io/g/cncf-cloudevents-sdk
- Contact for additional information: Denis Makogon (
@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.