定制 phariscope/event-store 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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:

  1. Create your own Store implementing the StoreInterface.
  2. 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_sqlite extension 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-memory
    • sqlite:/absolute/path/to/file.sqlite for 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:

  1. Register the bundle (Symfony Flex may do this automatically):
// config/bundles.php
return [
    // ...
    Phariscope\EventStore\Bridge\Symfony\EventStoreBundle::class => ['all' => true],
];
  1. 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: configured PDO instance
  • phariscope_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

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 phariscope/event-store 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3.6k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 15
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-25