utopia-php/cloudevents
Composer 安装命令:
composer require utopia-php/cloudevents
包简介
Lite & fast micro PHP CloudEvents implementation that is **easy to use**.
README 文档
README
Utopia CloudEvents is a modern PHP 8.3 implementation of the CloudEvents v1.0 specification. It provides a simple, type-safe way to work with CloudEvents in your PHP applications.
Although part of the Utopia Framework family, the library is framework-agnostic and can be used in any PHP project.
Installation
composer require utopia-php/cloudevents
The library requires PHP 8.3+.
What are CloudEvents?
CloudEvents is a specification for describing event data in a common way. It provides a standardized format for event producers and consumers to communicate, making it easier to build event-driven architectures.
Learn more at the CloudEvents specification.
Quick Start
Creating a CloudEvent
<?php require __DIR__ . '/vendor/autoload.php'; use Utopia\CloudEvents\CloudEvent; $event = new CloudEvent( specversion: '1.0', type: 'user.created', source: 'user-service', subject: 'user-123', id: uniqid(), time: date('c'), datacontenttype: 'application/json', data: [ 'userId' => '123', 'email' => 'user@example.com', 'name' => 'John Doe' ] );
Converting to Array
$eventArray = $event->toArray(); // Array with all CloudEvent fields
Creating from Array
$eventData = [ 'specversion' => '1.0', 'type' => 'user.created', 'source' => 'user-service', 'subject' => 'user-123', 'id' => 'unique-id', 'time' => '2025-11-07T10:00:00Z', 'datacontenttype' => 'application/json', 'data' => [ 'userId' => '123', 'email' => 'user@example.com' ] ]; $event = CloudEvent::fromArray($eventData);
Validating a CloudEvent
try { $event->validate(); echo "Event is valid!"; } catch (InvalidArgumentException $e) { echo "Event validation failed: " . $e->getMessage(); }
CloudEvent Properties
The CloudEvent class supports the following properties according to the CloudEvents v1.0 specification:
- specversion (required): CloudEvents specification version (default: "1.0")
- type (required): Event type identifier (e.g., "user.created", "v1-stats-usage")
- source (required): Context in which the event occurred (e.g., service name)
- subject (optional): Subject of the event (e.g., project ID, user ID)
- id (required): Unique identifier for the event
- time (required): Timestamp when the event occurred (RFC3339 format)
- datacontenttype (optional): Content type of the data field (default: "application/json")
- data (required): Event payload as an array
Use Cases
- Event-Driven Architecture: Standardize event formats across microservices
- Message Queues: Send CloudEvents via RabbitMQ, Kafka, or other message brokers
- Webhooks: Deliver CloudEvents to external systems
- Event Sourcing: Store cloudevents in a standardized format
- Serverless Functions: Trigger functions with CloudEvents
Development
- Install dependencies:
composer install - Static analysis:
composer check - Coding standards:
composer lint(usecomposer formatto auto-fix) - Tests:
composer test
License
MIT
utopia-php/cloudevents 适用场景与选型建议
utopia-php/cloudevents 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 85.69k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「php」 「upf」 「cloudevents」 「utopia」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 utopia-php/cloudevents 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 utopia-php/cloudevents 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 utopia-php/cloudevents 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
Lite & fast micro PHP test framework that is **easy to use**.
A simple, light and advanced PHP HTTP framework
A simple library providing a query abstraction for filtering, ordering, and pagination
Light & simple Circuit Breaker for PHP to prevent cascading failures in distributed systems.
A simple AB Test library to manage server side AB testing
统计信息
- 总下载量: 85.69k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-07