harrisonde / sdk-php

PHP SDK for CloudEvents

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PHP SDK for CloudEvents

Status

This SDK is currently a work in progress, therefore things might (and will) break with every update.

This SDK aims to supports the following versions of CloudEvents:

Installation

Install the SDK using composer:

composer require cloudevents/sdk-php

Send your first CloudEvent

Note, this is just the desired API at this point and doesn't reflect the functionality of this SDK yet.

use \CloudEvents\Client;
use \CloudEvents\V1\CloudEvent;
use \CloudEvents\Request;

$event = (new CloudEvent())
    // The current implementation requires you to maintain your own id.
    ->setId('1n6bFxDMHZFChlI4TVI9tdzphB9')
    ->setSource('/examples/php-sdk')
    ->setType('com.example.type')
    ->setData(json_encode(['example' => 'first-event']));

(new Client('http://localhost:8080/'))
    ->sendRequest(new Request($event));

Note that the CloudEvents\Client implements the PSR-18 spec and the CloudEvents\Request implements the appropriate PSR-7 interfaces.

Serialize/Deserialize a CloudEvent

use CloudEvents\Serializers\JsonSerializer;
use \CloudEvents\V1\CloudEvent;

$event = (new CloudEvent())
    // The current implementation requires you to maintain your own id.
    ->setId('1n6bFxDMHZFChlI4TVI9tdzphB9')
    ->setSource('/examples/php-sdk')
    ->setType('com.example.type')
    ->setData(json_encode(['example' => 'first-event']));

// JSON serialization
$serializer = new JsonSerializer();
$serializer->serialize($event);

// TODO: deserilization

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
  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

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.

About

PHP SDK for CloudEvents

License:Apache License 2.0


Languages

Language:PHP 88.4%Language:Dockerfile 8.0%Language:Shell 3.6%