auditor 4.3.0
✨ What's new
Custom audit representation for Doctrine types
Introduces the NeedsConversionToAuditableType interface, allowing Doctrine type authors
to decouple their audit representation from their database representation.
Previously, the auditor always called convertToDatabaseValue() to produce the value
stored in the diffs column. This caused two practical problems:
- Binary / non-UTF-8 data — types storing binary or encrypted data produce values
that cannot be safely JSON-encoded, corrupting thediffscolumn. - Audit ≠ storage — the value written to the database (e.g. a hashed password,
a serialised object) is sometimes intentionally different from what should appear
in the audit trail.
A Doctrine type implementing NeedsConversionToAuditableType provides a
convertToAuditableValue() method that the auditor calls instead of
convertToDatabaseValue() when building diffs.
use DH\Auditor\Transaction\NeedsConversionToAuditableType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
final class BinaryStringType extends Type implements NeedsConversionToAuditableType
{
// ...
public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string
{
return $value?->getBinary(); // raw binary — not audit-safe
}
public function convertToAuditableValue(mixed $value, AbstractPlatform $platform): string
{
return $value?->toBase64(); // human-readable audit representation
}
}What's Changed
New features
- feat: allow custom Doctrine types to define their own audit representation by @byfareska in #309
Documentation
- docs: add guide for building a custom provider
References
Full Changelog: 4.2.0...4.3.0