PHPackages                             juststeveking/cloudevents - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. juststeveking/cloudevents

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

juststeveking/cloudevents
=========================

Cloud Events in PHP.

0.0.1(1y ago)42MITPHPPHP ^8.4CI passing

Since Mar 14Pushed 1y ago1 watchersCompare

[ Source](https://github.com/JustSteveKing/cloudevents)[ Packagist](https://packagist.org/packages/juststeveking/cloudevents)[ Docs](https://github.com/juststeveking/cloudevents)[ GitHub Sponsors](https://github.com/juststeveking)[ RSS](/packages/juststeveking-cloudevents/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

Cloud Events PHP
================

[](#cloud-events-php)

[![Latest Version](https://camo.githubusercontent.com/2e2fdf916c70b1d16e5964944d5324b6e848fda9613d48896547c65120eddd2b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a75737473746576656b696e672f636c6f75646576656e74732e7376673f7374796c653d666c61742d737175617265266c6162656c3d72656c65617365)](https://packagist.org/packages/juststeveking/cloudevents)[![PHP Version](https://camo.githubusercontent.com/79928df8879f262878a679593e14f0eb69b67fe6fb382dadfd44060c856bb12d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6a75737473746576656b696e672f636c6f75646576656e74732e7376673f7374796c653d666c61742d737175617265)](https://php.net)[![Tests](https://github.com/JustSteveKing/cloudevents/actions/workflows/ci.yml/badge.svg)](https://github.com/JustSteveKing/cloudevents/actions/workflows/ci.yml)[![Total Downloads](https://camo.githubusercontent.com/98e1c29cd596e9386e7e9680f68f7719863c55aed524ed322d2c91110d956f6d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a75737473746576656b696e672f636c6f75646576656e74732e7376673f7374796c653d666c61742d73717561726526636f6c6f72423d6d656469756d76696f6c6574726564)](https://packagist.org/packages/juststeveking/cloudevents)

Welcome to the **Cloud Events PHP** repository! This library enables you to create and manage [Cloud Events](https://cloudevents.io/) in PHP with ease.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
- [Features](#features)
- [Properties](#properties)
- [Why Cloud Events?](#why-cloud-events)
- [Examples](#examples)
    - [Distributed Systems Communication](#distributed-systems-communication)
    - [Audit Trail &amp; Logging](#audit-trail--logging)
    - [Integration Scenarios](#integration-scenarios)
    - [Common Use Cases](#common-use-cases)
    - [Example 1: User Registration Event](#example-1-user-registration-event)
    - [Example 2: Order Created Event](#example-2-order-created-event)
    - [Example 3: File Upload Event](#example-3-file-upload-event)
- [Contributing](#contributing)
- [License](#license)

Installation
------------

[](#installation)

Install the library via Composer:

```
composer require juststeveking/cloudevents
```

Usage
-----

[](#usage)

Here's a basic example of how to create a Cloud Event:

```
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',
);
```

You can also pass through an array to the static `make` method:

```
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',
]);
```

Features
--------

[](#features)

- Easy creation and management of Cloud Events
- Flexible event data structure

Properties
----------

[](#properties)

- `id`: Identifies the event. Producers MUST ensure that source + id is unique for each distinct event. If a duplicate event is re-sent (e.g. due to a network error) it MAY have the same id. Consumers MAY assume that Events with identical source and id are duplicates.
- `source`: Identifies the context in which an event happened. Often this will include information such as the type of the event source, the organization publishing the event or the process that produced the event. The exact syntax and semantics behind the data encoded in the URI is defined by the event producer.
- `type`: This attribute contains a value describing the type of event related to the originating occurrence. Often this attribute is used for routing, observability, policy enforcement, etc. The format of this is producer defined and might include information such as the version of the type.
- `data`: The data you want to send in the cloud event.
- `dataContentType`: Content type of data value. This attribute enables data to carry any type of content, whereby format and encoding might differ from that of the chosen event format. For example, an event rendered using the JSON envelope format might carry an XML payload in data, and the consumer is informed by this attribute being set to "application/xml". The rules for how data content is rendered for different datacontenttype values are defined in the event format specifications; for example, the JSON event format defines the relationship in section 3.1.
- `dataSchema`: Identifies the schema that data adheres to. Incompatible changes to the schema SHOULD be reflected by a different URI. See Versioning of CloudEvents in the Primer for more information.
- `subject`: This describes the subject of the event in the context of the event producer (identified by source). In publish-subscribe scenarios, a subscriber will typically subscribe to events emitted by a source, but the source identifier alone might not be sufficient as a qualifier for any specific event if the source context has internal sub-structure.
- `time`: Timestamp of when the occurrence happened. If the time of the occurrence cannot be determined then this attribute MAY be set to some other time (such as the current time) by the CloudEvents producer, however all producers for the same source MUST be consistent in this respect. In other words, either they all use the actual time of the occurrence or they all use the same algorithm to determine the value used.

Why Cloud Events?
-----------------

[](#why-cloud-events)

CloudEvents is a specification for describing event data in a common way. This allows for interoperability between services and systems that produce and consume events. The specification is designed to be language agnostic and is supported by a wide range of programming languages and frameworks. This is the PHP implementation that makes sense to me.

Examples
--------

[](#examples)

Here are some examples of how you could use this library to create Cloud Events. When are cloud events are useful? They're standardized ways to describe events in any cloud-native system, and they're valuable in several scenarios:

### Distributed Systems Communication

[](#distributed-systems-communication)

- When you have multiple services that need to communicate asynchronously
- For microservices architectures where events flow between different components
- When integrating with cloud providers' event-driven services

### Audit Trail &amp; Logging

[](#audit-trail--logging)

- Tracking important business events (user signups, orders, payments)
- Creating consistent logging formats across different systems
- Maintaining a record of system-wide state changes

### Integration Scenarios

[](#integration-scenarios)

- When connecting with third-party services
- For webhook implementations
- Building event-driven APIs

### Common Use Cases:

[](#common-use-cases)

- User actions (registration, login, profile updates)
- Business transactions (orders, payments, refunds)
- System events (backup completed, error occurred)
- Resource state changes (document updated, image processed)

The key benefit is that cloud events provide a consistent, standardized format for event data across different systems and platforms, making it easier to build reliable, interoperable event-driven architectures.

### Example 1: User Registration Event

[](#example-1-user-registration-event)

You may wish to dispatch an event when a user registers on your platform. Here's an example of how you could create a Cloud Event for this:

```
use JustSteveKing\CloudEvents\CloudEvent;

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

### Example 2: Order Created Event

[](#example-2-order-created-event)

You may wish to dispatch an event when an order is created on your platform. Here's an example of how you could create a Cloud Event for this:

```
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',
]);
```

### Example 3: File Upload Event

[](#example-3-file-upload-event)

You may wish to dispatch an event when a file is uploaded to your platform. Here's an example of how you could create a Cloud Event for this:

```
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'
]);
```

License
-------

[](#license)

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance45

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

430d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a87fe82b349821ebd49cf57d65c4cd3e33ae0833222a8438d90fe8921ca899ea?d=identicon)[JustSteveKing](/maintainers/JustSteveKing)

---

Top Contributors

[![JustSteveKing](https://avatars.githubusercontent.com/u/6368379?v=4)](https://github.com/JustSteveKing "JustSteveKing (7 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/juststeveking-cloudevents/health.svg)

```
[![Health](https://phpackages.com/badges/juststeveking-cloudevents/health.svg)](https://phpackages.com/packages/juststeveking-cloudevents)
```

###  Alternatives

[magyarjeti/laravel-lipsum

Lorem ipsum generator for Laravel Framework

1617.9k](/packages/magyarjeti-laravel-lipsum)[ibrahimbougaoua/radiobuttonimage

This is my package radiobuttonimage

166.0k](/packages/ibrahimbougaoua-radiobuttonimage)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
