packagist damienharper/auditor 4.3.0

6 hours ago

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:

  1. Binary / non-UTF-8 data — types storing binary or encrypted data produce values
    that cannot be safely JSON-encoded, corrupting the diffs column.
  2. 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

Don't miss a new auditor release

NewReleases is sending notifications on new releases.