gember/event-sourcing-universal-service-provider
Composer 安装命令:
composer require gember/event-sourcing-universal-service-provider
包简介
Universal service provider for Gember Event Sourcing (gember/event-sourcing)
关键字:
README 文档
README
Universal Service Provider for Gember Event Sourcing , compatible with any application or framework that supports container-interop/service-provider.
Installation
Install the service provider with composer:
composer require gember/event-sourcing-universal-service-provider
Configuration
This package installs Gember Event Sourcing with all required dependency adapters. Some of these adapters need to be configured.
By default, it uses the following configuration:
PSR-11 Container definition (https://www.php-fig.org/psr/psr-11):
use Doctrine\DBAL\Connection; use Gember\IdentityGeneratorSymfony\Ulid\SymfonyUuidIdentityGenerator; use Psr\Container\ContainerInterface; use Symfony\Component\Serializer\Serializer; return [ 'gember_event_sourcing' => fn(ContainerInterface $container) => [ 'message_bus' => [ 'symfony' => [ 'event_bus' => $container->get('event.bus'), ], ], 'cache' => [ 'enabled' => false, // set a PSR-6 or PSR-16 implementation // 'psr16' => $container->get('cache.file'), // 'psr6' => $container->get('cache.file'), ], 'serializer' => [ 'symfony' => [ 'serializer' => $container->get(Serializer::class), ], ], 'event_store' => [ 'rdbms' => [ 'doctrine_dbal' => [ 'connection' => $container->get(Connection::class), ], ], ], 'generator' => [ 'identity' => [ 'service' => $container->get(SymfonyUuidIdentityGenerator::class), // or use ULIDs // 'service' => $container->get(SymfonyUlidIdentityGenerator::class), ], ], 'registry' => [ 'event' => [ 'reflector' => [ 'path' => '/path/to/src', // default: getcwd() . '/../src' ], ], 'command_handler' => [ 'reflector' => [ 'path' => '/path/to/src', // default: getcwd() . '/../src' ], ], ], ], ];
You can override any of these defaults however you like.
Required dependencies
Some of the required dependencies also need to be configured separately.
Symfony Messenger (symfony/messenger)
The default configuration makes use of a service with name event.bus.
When this bus is configured, Gember Event Sourcing works out of the box.
However, when a different event bus is preferred, it must be a service implementing Symfony\Component\Messenger\MessageBusInterface.
Example (minimum) configuration for symfony/messenger:
PSR-11 Container definition (https://www.php-fig.org/psr/psr-11):
use Psr\Container\ContainerInterface; use Symfony\Component\Messenger\Handler\HandlerDescriptor; use Symfony\Component\Messenger\Handler\HandlersLocator; use Symfony\Component\Messenger\MessageBus; use Symfony\Component\Messenger\Middleware\HandleMessageMiddleware; return [ 'event.bus' => fn(ContainerInterface $container) => new MessageBus([ new HandleMessageMiddleware(new HandlersLocator([ // Ideally this could be autoconfigured SomeDomainEvent::class => [ new HandlerDescriptor([ $container->get(SomeProjector::class), 'onSomeDomainEvent' ]), ], ]), allowNoHandlers: true), ]), ];
Symfony Cache (symfony/cache)
The default configuration makes use of a service with name cache.file.
When this cache service is configured, Gember Event Sourcing works out of the box.
However, when a different cache pool is preferred, it must be a service implementing Psr\Cache\CacheItemPoolInterface (PSR-6) or Psr\SimpleCache\CacheInterface (PSR-16).
Example (minimum) configuration for symfony/cache:
PSR-11 Container definition (https://www.php-fig.org/psr/psr-11):
use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\Cache\Psr16Cache; return [ 'cache.file' => fn() => new Psr16Cache(new FilesystemAdapter( directory: __DIR__ . '/../../var/cache', )), ];
Symfony Serializer (symfony/serializer)
The default configuration makes use of a service with name Symfony\Component\Serializer\Serializer.
When this serializer service is configured, Gember Event Sourcing works out of the box.
However, when a different serializer is preferred, it must be a service implementing Symfony\Component\Serializer\SerializerInterface.
Example (minimum) configuration for symfony/serializer:
PSR-11 Container definition (https://www.php-fig.org/psr/psr-11):
use Symfony\Component\Serializer\Encoder\JsonEncoder; use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Component\Serializer\Serializer; return [ Serializer::class => fn() => new Serializer([ new DateTimeNormalizer([ DateTimeNormalizer::FORMAT_KEY => 'Y-m-d\TH:i:s.uP', ]), new ObjectNormalizer(), ], [ new JsonEncoder(), ]), ];
Doctrine DBAL/ORM (doctrine/dbal, doctrine/orm)
The default configuration makes use of a service with name Doctrine\DBAL\Connection.
When this connection service is configured, Gember Event Sourcing works out of the box.
However, when a different Doctrine connection is preferred, it must be a service implementing Doctrine\DBAL\Connection.
Example (minimum) configuration for doctrine/dbal:
PSR-11 Container definition (https://www.php-fig.org/psr/psr-11):
use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; return [ Connection::class => fn() => DriverManager::getConnection([ 'host' => $_ENV['DB_HOST'], 'port' => $_ENV['DB_PORT'], 'dbname' => $_ENV['DB_DBNAME'], 'user' => $_ENV['DB_USER'], 'password' => $_ENV['DB_PASSWORD'], 'driver' => $_ENV['DB_DRIVER'], 'charset' => $_ENV['DB_CHARSET'], ]), ];
Database
In order to persist all domain events in database, a running SQL database is needed. The event store requires two tables. Schema is available in either raw SQL or in a migration file format:
Raw SQL schema: https://github.com/GemberPHP/rdbms-event-store-doctrine-dbal/blob/main/resources/schema.sql
Migrations:
- Doctrine migrations: https://github.com/GemberPHP/rdbms-event-store-doctrine-dbal/blob/main/resources/migrations/doctrine
- Phinx migrations: https://github.com/GemberPHP/rdbms-event-store-doctrine-dbal/tree/main/resources/migrations/phinx
Good to go!
Check the main package gember/event-sourcing or the demo application gember/example-event-sourcing-dcb for examples.
gember/event-sourcing-universal-service-provider 适用场景与选型建议
gember/event-sourcing-universal-service-provider 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 05 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「service-provider」 「ddd」 「container-interop」 「event-sourcing」 「domain-driven-design」 「gember」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gember/event-sourcing-universal-service-provider 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gember/event-sourcing-universal-service-provider 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gember/event-sourcing-universal-service-provider 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Runn Me! Value Objects Library
WordPress® Settings API service provider
Build a domain-oriented application on Laravel Framework
Symfony bundle for broadway/broadway.
Provides Symfony param converters for mediagone/types-common package.
Symfony compiler pass that allows to use service providers as defined in container-interop/service-provider
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-06