Download the PHP package ez-php/audit without Composer
On this page you can find all versions of the php package ez-php/audit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package audit
Short Description Audit log module for ez-php — event-driven recording of entity lifecycle changes (CREATE, UPDATE, DELETE) into an audit_logs table with a fluent query API.
License MIT
Informations about the package audit
ez-php/audit
Event-driven audit log module for ez-php. Records entity lifecycle changes (CREATE, UPDATE, DELETE) to a database table and exposes a fluent query API.
Installation
Register the service provider:
AuditServiceProvider requires DatabaseInterface and ez-php/events (EventServiceProvider) to be registered before it.
Database Schema
The module auto-creates the audit_logs table on first write (ensureTable()). For production use, prefer running a migration:
Usage
Dispatching audit events from repositories
Audit records are created by dispatching events from repository methods:
AuditServiceProvider registers AuditListener automatically — no manual listener registration needed.
Querying the audit trail
All filter methods return a clone — chaining does not modify the original query.
Programmatic logging (without events)
Design
Integration via events, not ORM core. Repositories dispatch EntityCreatedEvent, EntityUpdatedEvent, and EntityDeletedEvent. AuditListener (registered by the service provider) converts them to AuditRecord and writes to the database. No ORM kernel changes required.
AuditQuery is immutable. All filter methods (action(), since(), until(), byUser(), limit()) return a clone. Re-use the same base query safely.
ensureTable() for zero-config development. AuditLogger auto-creates audit_logs on first write, adapting DDL to the PDO driver (SQLite for tests, MySQL for production). Production deployments should prefer a migration.
No hard ORM dependency. Depends only on ez-php/contracts and ez-php/events. Works with any persistence mechanism that dispatches the provided event types.
API Reference
AuditAction (enum)
| Case | Value |
|---|---|
AuditAction::CREATE |
'create' |
AuditAction::UPDATE |
'update' |
AuditAction::DELETE |
'delete' |
AuditRecord (value object)
| Property | Type | Description |
|---|---|---|
entityType |
string |
Class name or identifier |
entityId |
string |
Primary key (cast to string) |
action |
AuditAction |
What happened |
oldValues |
array<string, mixed> |
Before-state (empty for creates) |
newValues |
array<string, mixed> |
After-state (empty for deletes) |
userId |
string\|null |
Who triggered the change |
createdAt |
DateTimeImmutable |
When it happened |
Static factories: AuditRecord::fromCreated(), ::fromUpdated(), ::fromDeleted().
AuditQuery (fluent query builder)
| Method | Description |
|---|---|
AuditQuery::for(class, id) |
Scope to entity; returns new query |
->action(AuditAction) |
Filter by action type |
->since(DateTimeImmutable) |
Filter by minimum created_at |
->until(DateTimeImmutable) |
Filter by maximum created_at |
->byUser(int\|string) |
Filter by user_id |
->limit(int) |
Limit result count |
->get() |
Execute; return list<AuditRecord> |
->first() |
Return latest record or null |
->count() |
Return total count |
Events
| Class | When to dispatch |
|---|---|
EntityCreatedEvent |
Entity created |
EntityUpdatedEvent |
Entity updated |
EntityDeletedEvent |
Entity deleted |
All versions of audit with dependencies
ez-php/console Version ^2.0
ez-php/contracts Version ^2.0
ez-php/events Version ^2.0