PHP code example of juststeveking / cloudevents

1. Go to this page and download the library: Download juststeveking/cloudevents library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

juststeveking / cloudevents example snippets


use JustSteveKing\CloudEvents\CloudEvent;

$event = new CloudEvent(
    id => '1234',
    source => '/some-url',
    type => 'com.vendor.action.event',
    data => json_encode(['foo' => 'bar'], JSON_THROW_ON_ERROR),
    dataContentType => 'application/json',
    data_schema => null,
    subject => 'cloud-event.json',
    time => '01/01/1234',
);

use JustSteveKing\CloudEvents\CloudEvent;

$event = CloudEvent::make([
    'id' => '1234',
    'source' => '/some-url',
    'type' => 'com.vendor.action.event',
    'data' => json_encode(['foo' => 'bar'], JSON_THROW_ON_ERROR),
    'data_content_type' => 'application/json',
    'dataSchema' => null,
    'subject' => 'cloud-event.json',
    'time' => '01/01/1234',
]);

use JustSteveKing\CloudEvents\CloudEvent;

$registrationEvent = CloudEvent::make([
    'id' => uniqid(),
    'source' => '/auth/register',
    'type' => 'com.example.user.registered',
    'data' => json_encode([
        'user_id' => 123,
        'email' => '[email protected]',
        'registered_at' => '2023-01-01T12:00:00Z'
    ]),
    'dataContentType' => 'application/json',
]);

use JustSteveKing\CloudEvents\CloudEvent;

$orderEvent = CloudEvent::make([
    'id' => uniqid(),
    'source' => '/orders',
    'type' => 'com.example.order.created',
    'data' => json_encode([
        'order_id' => 'ORD-123',
        'customer_id' => 456,
        'total' => 99.99,
        'items' => ['SKU-1', 'SKU-2']
    ]),
    'dataContentType' => 'application/json',
]);

use JustSteveKing\CloudEvents\CloudEvent;

$uploadEvent = CloudEvent::make([
    'id' => uniqid(),
    'source' => '/storage/files',
    'type' => 'com.example.file.uploaded',
    'data' => json_encode([
        'file_name' => 'document.pdf',
        'size' => 1024567,
        'mime_type' => 'application/pdf',
        'storage_path' => '/uploads/2023/01/document.pdf'
    ]),
    'dataContentType' => 'application/json',
    'subject' => 'document.pdf'
]);