event-engine/php-persistence
Event Engine PHP Persistence Package providing persistence layer utilities for PHP-based event-sourced and CQRS applications. Supports storing and retrieving events and state in a consistent way to integrate with Event Engine workflows.
## Technical Evaluation
### **Architecture Fit**
- **Event Sourcing/CQRS Alignment**: Unchanged. The package remains optimized for event-sourced architectures and CQRS, with no architectural modifications. PHP 8 support and deprecation removals are **non-functional changes** that do not alter its core design or Laravel/DDD alignment.
- **Laravel Compatibility**: No architectural shifts. The package continues to **augment or replace** Laravel’s native event system, requiring explicit adoption of event-driven workflows. The removal of PHP 8.4 deprecations ensures compatibility with modern Laravel stacks (v10+) but does not introduce new Laravel-specific integrations.
- **Domain-Specific Needs**: Still ideal for **audit trails, replayability, or eventual consistency**. CRUD-heavy applications remain a poor fit due to inherent complexity.
### **Integration Feasibility**
- **Database Schema**: No changes to schema requirements. Custom tables (e.g., `events`, `aggregates`) are still mandatory, with Laravel Migrations as the primary tool. No new conflicts introduced.
- **ORM Interaction**: Persistent reliance on **raw SQL or non-Eloquent layers** remains. Integration with Laravel’s ORM (e.g., querying aggregates via Eloquent) still may require wrappers or adapters.
- **Event Dispatching**: Asynchronous persistence assumptions unchanged. Laravel’s synchronous `Event` system may still conflict, necessitating custom listeners or hybrid approaches.
### **Technical Risk**
- **Lock-in to Event Model**: Risk remains unchanged. Heavy reliance on the package still couples the app to event-sourcing patterns, complicating future migrations.
- **Performance Overhead**: No performance-related changes. Benchmarking against Laravel’s native event system remains critical.
- **Tooling Gaps**: Lack of Laravel-specific tooling (e.g., Scout for event search) persists. Custom solutions may still be required.
- **Testing Complexity**: Temporal testing requirements (e.g., event replay) remain unchanged and may still clash with Laravel’s testing helpers.
- **PHP 8.4 Deprecation Handling**: **New Risk**. The removal of PHP 8.4 deprecations (e.g., `create_function`, `call_user_func_array` with variadic args) may expose **hidden dependencies** in the Laravel ecosystem or third-party packages. Audit for:
- Legacy code using deprecated functions.
- Laravel plugins or packages relying on removed features.
### **Key Questions**
1. **PHP 8 Compatibility**:
- Does the app use **PHP 8 features** (e.g., attributes, union types) that could interact with the package’s updated support? Test for:
- Constructor property promotion.
- Named arguments in method calls.
- Edge cases in event handler signatures (e.g., `void` return types).
2. **PHP 8.4 Deprecation Impact**:
- Were **PHP 8.4 deprecations** (e.g., `create_function`, `call_user_func_array` with variadic args) used in:
- Laravel’s core or third-party packages?
- Custom event handlers or middleware?
- Legacy migrations or Artisan commands?
3. **Laravel Event System Conflict** *(Unchanged)*:
- Clarify whether this package will **replace** or **coexist** with Laravel’s `Event` facade.
4. **Database Strategy** *(Unchanged)*:
- Confirm transaction handling (e.g., ACID guarantees for event-aggregate pairs) and backup/recovery plans.
5. **Scaling Assumptions** *(Unchanged)*:
- Verify support for **sharding** or **multi-DB setups**, especially if Laravel’s single-DB default is insufficient.
6. **Third-Party Package Conflicts**:
- Audit for packages using **removed PHP 8.4 functions** (e.g., `create_function`). Example: Laravel Echo, Horizon, or custom event listeners.
---
## Integration Approach
### **Stack Fit**
- **PHP/Laravel**:
- **PHP 8 Support**: Officially validated. Update `composer.json` to require `^8.0` and test:
- Constructor property promotion in event handlers.
- Named arguments in method calls (e.g., `EventStore::persist($event, $metadata)`).
- New PHP 8.1+ features (e.g., `array_unpack`) if used in projections.
- **PHP 8.4 Deprecation Cleanup**: Critical for Laravel 11+ compatibility. Audit:
- Laravel’s core (e.g., `Illuminate\Support\Facades\Event`).
- Third-party packages (e.g., `laravel-echo`, `spatie/laravel-event-sourcing`).
- **Service Container**: Extend Laravel’s container to bind package dependencies (e.g., `EventStore`, `ProjectionManager`) if not auto-discovered.
- **Database**:
- No changes to database assumptions. Schema migrations remain critical for custom tables.
- Leverage Laravel’s **DBAL** for raw SQL interactions if the package uses non-Eloquent queries.
- **Queue System**:
- Asynchronous event persistence assumptions unchanged. Use Laravel’s **queue workers** (Redis, database) for consistency.
### **Migration Path**
1. **PHP Version Upgrade** *(New)*:
- Update `php.ini` and `composer.json` to PHP 8.0+.
- Run `composer update` and test for:
- Deprecation warnings (e.g., `array_merge` behavior changes).
- Constructor property promotion errors in event handlers.
2. **Pilot Feature** *(Unchanged)*:
- Test with a non-critical module (e.g., order processing) to validate:
- PHP 8 compatibility.
- Performance (no regressions from PHP 8.4 cleanup).
3. **Hybrid Integration** *(Unchanged)*:
- Route critical events to the package while keeping Laravel’s `Event` system for non-critical paths.
4. **Full Adoption** *(Unchanged)*:
- Replace `Event::dispatch()` with the package’s API (`EventStore::persist()`) for new features.
- Deprecate old event listeners in favor of aggregate/event handlers.
### **Compatibility**
- **Laravel Versions**:
- **Laravel 10/11**: Confirm compatibility. Test:
- Service provider bootstrapping (e.g., `register()` vs. `boot()`).
- Facade/class name collisions (e.g., `Event` vs. `EventStore`).
- **PHP 8.4 deprecation fallout**: Audit Laravel’s core for removed functions (e.g., `create_function` in `Illuminate\Support\Str`).
- **Third-Party Packages**:
- Check for conflicts with packages using **PHP 8.4 deprecations**:
- `laravel-echo` (WebSocket event handling).
- `spatie/laravel-event-sourcing` (alternative event store).
- Custom event listeners using `call_user_func_array`.
- Update or replace conflicting packages.
- **Caching**:
- Projection caching (if used) should align with Laravel’s **cache drivers** (Redis, file). No changes required.
### **Sequencing**
1. **Infrastructure Setup** *(Unchanged)*:
- Configure event tables, indexes, and storage backends (e.g., S3).
2. **PHP 8 Migration** *(New)*:
- Update `php.ini` and `composer.json` to PHP 8.0+.
- Run static analysis (`phpstan`, `psalm`) for PHP 8 compatibility.
3. **Core Integration** *(Updated)*:
- Replace `Event::dispatch()` with the package’s API in critical paths.
- Audit for **PHP 8.4 deprecations** in event handlers/middleware.
4. **Projection Layer** *(Unchanged)*:
- Implement read models querying projections, not raw events.
5. **Testing** *(Updated)*:
- Add **PHP 8-specific tests**:
- Constructor property promotion.
- Union types in event payloads.
- Deprecation warnings (if any).
- Write event replay tests using Laravel’s `DatabaseMigrations` + custom helpers.
6. **Monitoring** *(Unchanged)*:
- Track event persistence health (e.g., `last_event_id`).
---
## Operational Impact
### **Maintenance**
- **Schema Evolution** *(Unchanged)*:
- Backward-compatible migrations remain critical. Use Laravel’s schema dumps.
- **Dependency Updates** *(Updated)*:
- Pin the package version in `composer.json` if stability is critical.
- **Audit for PHP 8.4 deprecations** in:
- Laravel’s core (e.g., `Illuminate\Support\Facades\Event`).
- Third-party packages (e.g., `laravel-echo`).
- Monitor for **PHP 8.1/8.2 deprecations** in future Laravel updates (e.g., `array_merge` behavior changes).
- **Documentation** *(Updated)*:
- Update internal runbooks to reflect:
- **PHP 8 requirements** (e.g., constructor syntax).
- **PHP 8.4 deprecation workarounds** (e.g., replacing `create_function`).
- Document **event handler compatibility** with PHP 8 features (e.g., union types).
### **Support**
- **Debugging Complexity** *(Unchanged)*:
- Temporal debugging tools (e.g., Laravel Telescope) remain essential.
- **Common
How can I help you explore Laravel packages today?