phariscope/event-store
Composer 安装命令:
composer require phariscope/event-store
包简介
To develop event stores this package is start base.
关键字:
README 文档
README
composer require phariscope/event-store
Supported versions
| Supported | |
|---|---|
| PHP | >=8.1 (Symfony 8 requires PHP >=8.4 on the application side; Composer will resolve accordingly) |
Symfony (config, dependency-injection, http-kernel, serializer, yaml) |
6.4 LTS, 7.x, and 8.x per composer.json |
| phariscope/event | >=1.2 (1.2.x is the reference line used in CI) |
Continuous integration runs PHPUnit against Symfony 6.4, 7.4, and 8.0 lines (see .github/workflows/ci.yml).
Usage
There is no direct usage for this package. You should use this package only if you want to develop your own event storage component.
To develop your own storage:
- Create your own Store implementing the StoreInterface.
- Create your subscriber by extending PersistEventSubscriberAbstract, which can be constructed with your store.
Multiple implementations of the StoreInterface are provided:
- StoreEventInMemory: In-memory storage for testing and development
- StoreEventInDatabase: Persistent database storage using PDO
- StoreEventWithMetrics: Decorator adding performance monitoring to any store
Using the SQLite persistence listener
A ready-to-use listener is provided to persist every event into a SQLite database (or any PDO-supported database) using StoreEventInDatabase under the hood.
Prerequisites:
- PHP with
pdo_sqliteextension enabled (or another PDO driver if you use a different DBMS)
Example:
use Phariscope\EventStore\Persistence\PersistEventInDatabaseSubscriber; // 1) Create a PDO connection (SQLite examples) $pdo = new PDO('sqlite:/absolute/path/to/events.sqlite'); // or in-memory for tests/dev: new PDO('sqlite::memory:'); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // 2) Create the persistence listener (table auto-created if missing) $persist = new PersistEventInDatabaseSubscriber($pdo, 'stored_events'); // 3) Use it as a PSR-14 listener/subscriber in your event system // Registration depends on your dispatcher implementation. // You can also invoke it directly: // $persist->handle($yourEvent); EventPublisher::instance()->subscribe($persist); // 4) Access the underlying store when needed $store = $persist->getStore(); // Fetch the last 10 stored events $lastTen = $store->allStoredEventsSince(10); // Fetch all events of a given type (optionally since a datetime or last N) // $eventsByType = $store->getEventsByType(YourEvent::class);
Notes:
- The table is created automatically with the name you provide (default:
stored_events). - SQLite DSN formats:
sqlite::memory:for in-memorysqlite:/absolute/path/to/file.sqlitefor file-backed
YAML configuration
You can configure the SQLite path and table name via a YAML file and build the listener from it.
Example config/event_store.yaml:
event_store: dsn: "sqlite:///absolute/path/to/events.sqlite" # or ":memory:" for in-memory table_name: "stored_events" # optional (default: stored_events)
Bootstrap from configuration:
use Phariscope\EventStore\Config\EventStoreConfiguration; use Phariscope\Event\Psr14\EventPublisher; $config = EventStoreConfiguration::fromFile(__DIR__ . '/config/event_store.yaml'); $subscriber = $config->createSubscriber(); EventPublisher::instance()->subscribe($subscriber);
Symfony Bundle integration
If you are using Symfony, enable the bundle and configure it under config/packages/event_store.yaml:
- Register the bundle (Symfony Flex may do this automatically):
// config/bundles.php return [ // ... Phariscope\EventStore\Bridge\Symfony\EventStoreBundle::class => ['all' => true], ];
- Configure the package:
# config/packages/event_store.yaml event_store: dsn: "sqlite:///absolute/path/to/events.sqlite" # or ":memory:" table_name: "stored_events" # optional
Services exposed:
phariscope_event_store.pdo: configuredPDOinstancephariscope_event_store.subscriber:PersistEventInDatabaseSubscriber
Additional features include:
- Event versioning with VersionedEvent for schema evolution
- Performance metrics tracking with EventStoreMetrics
- Event filtering by type and time ranges
- Comprehensive API documentation in docs/API.md
To Contribute to phariscope/Event
Requirements
- docker
- git
Install
- git clone git@github.com:phariscope/EventStore.git
Unit test
bin/phpunit
Using Test-Driven Development (TDD) principles (thanks to Kent Beck and others), following good practices (thanks to Uncle Bob and others) and the great book 'DDD in PHP' by C. Buenosvinos, C. Soronellas, K. Akbary
Quality
- phpcs PSR12
- phpstan level 9
- coverage 100%
- infection MSI 100%
Quick check with:
./codecheck
Check coverage with:
bin/phpunit --coverage-html var
and view 'var/index.html' with your browser
Check infection with:
bin/infection
and view 'var/infection.html' with your browser
phariscope/event-store 适用场景与选型建议
phariscope/event-store 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.6k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 09 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「templating」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 phariscope/event-store 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 phariscope/event-store 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 phariscope/event-store 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
A Processor for Markup written in PHP. Allows extraction of Markup into a data structure, orchestrated nested manipulation of said structure, and output as (optimized) Markup.
Melis Platform Templating Plugin Creator
Serpent is a lightweight and compiling templating engine for PHP. It was designed to seamlessly integrate into existing MVC frameworks. It uses PHP itself as its template language, so you do not need to learn a new markup language. On the other side you get many improvements compared to pure PHP.
The template engine.
Template language for PHP
统计信息
- 总下载量: 3.6k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-25