Upgrading to 4.x from 3.x
PHP 8.4+ modernization and new features
This document describes the backward incompatible changes introduced in auditor 4.0 and how to adapt your code.
⚠️ Requirements Changes
PHP Version
IMPORTANT
Minimum PHP version is now 8.4 (was 8.2 in 3.x)
This is required by Symfony 8.0 and leverages PHP 8.4 features.
Symfony Version
IMPORTANT
Minimum Symfony version is now 8.0 (was 5.4 in 3.x)
Support for Symfony 5.4, 6.4, and 7.x has been dropped.
Doctrine Versions
| Package | 3.x Version | 4.x Version |
|---|---|---|
| Doctrine DBAL | >= 3.2 | >= 4.0 |
| Doctrine ORM | >= 2.13 | >= 3.2 |
PHPUnit Version
PHPUnit minimum version is now 12.0 (was 11.0 in 3.x)
🗑️ Removed Methods
DoctrineHelper
The following methods have been removed from DH\Auditor\Provider\Doctrine\Persistence\Helper\DoctrineHelper:
| Removed Method | Replacement |
|---|---|
DoctrineHelper::createSchemaManager() | $connection->createSchemaManager() |
DoctrineHelper::introspectSchema() | $schemaManager->introspectSchema() |
DoctrineHelper::getMigrateToSql() | See migration example below |
These methods were compatibility shims for older Doctrine DBAL versions that are no longer needed.
📦 Namespace Changes
Annotation → Attribute
TIP
The Annotation namespace has been renamed to Attribute to align with PHP 8+ terminology.
| Before (3.x) | After (4.0) |
|---|---|
DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable | DH\Auditor\Provider\Doctrine\Auditing\Attribute\Auditable |
DH\Auditor\Provider\Doctrine\Auditing\Annotation\Ignore | DH\Auditor\Provider\Doctrine\Auditing\Attribute\Ignore |
DH\Auditor\Provider\Doctrine\Auditing\Annotation\Security | DH\Auditor\Provider\Doctrine\Auditing\Attribute\Security |
DH\Auditor\Provider\Doctrine\Auditing\Annotation\AnnotationLoader | DH\Auditor\Provider\Doctrine\Auditing\Attribute\AttributeLoader |
Before (3.x):
use DH\Auditor\Provider\Doctrine\Auditing\Annotation as Audit;
#[Audit\Auditable]
class MyEntity
{
#[Audit\Ignore]
private string $ignoredField;
}
After (4.0):
use DH\Auditor\Provider\Doctrine\Auditing\Attribute as Audit;
#[Audit\Auditable]
class MyEntity
{
#[Audit\Ignore]
private string $ignoredField;
}
Attribute → Core Namespace (4.x)
TIP
PHP attributes have been promoted to the core DH\Auditor\Attribute namespace to be provider-agnostic (e.g. for future Eloquent provider support). The old provider-specific classes are now deprecated but still work as they extend the new ones.
| Deprecated (4.x) | Canonical (4.x) |
|---|---|
DH\Auditor\Provider\Doctrine\Auditing\Attribute\Auditable | DH\Auditor\Attribute\Auditable |
DH\Auditor\Provider\Doctrine\Auditing\Attribute\Ignore | DH\Auditor\Attribute\Ignore |
DH\Auditor\Provider\Doctrine\Auditing\Attribute\Security | DH\Auditor\Attribute\Security |
Before (deprecated):
use DH\Auditor\Provider\Doctrine\Auditing\Attribute\Auditable;
use DH\Auditor\Provider\Doctrine\Auditing\Attribute\Ignore;
use DH\Auditor\Provider\Doctrine\Auditing\Attribute\Security;
After (canonical):
use DH\Auditor\Attribute\Auditable;
use DH\Auditor\Attribute\Ignore;
use DH\Auditor\Attribute\Security;
📊 Model Changes
Entry Model - Property Hooks (PHP 8.4+)
NOTE
The Entry model now uses PHP 8.4 property hooks. Getter methods have been replaced by direct property access.
| Before (3.x) | After (4.0) |
|---|---|
$entry->getId() | $entry->id |
$entry->getType() | $entry->type |
$entry->getObjectId() | $entry->objectId |
$entry->getDiscriminator() | $entry->discriminator |
$entry->getTransactionHash() | $entry->transactionHash |
$entry->getUserId() | $entry->userId |
$entry->getUsername() | $entry->username |
$entry->getUserFqdn() | $entry->userFqdn |
$entry->getUserFirewall() | $entry->userFirewall |
$entry->getIp() | $entry->ip |
$entry->getCreatedAt() | $entry->createdAt |
| (new) | $entry->extraData |
Note: getDiffs() and getExtraData() methods remain as they contain business logic. extraData is also available as a virtual property.
Configuration - Asymmetric Visibility (PHP 8.4+)
The Configuration class now uses PHP 8.4 asymmetric visibility:
| Before (3.x) | After (4.0) |
|---|---|
$config->isEnabled() | $config->enabled |
$config->getTimezone() | $config->timezone |
User Model - Property Hooks (PHP 8.4+)
The UserInterface now uses PHP 8.4 property hooks:
| Before (3.x) | After (4.0) |
|---|---|
$user->getIdentifier() | $user->identifier |
$user->getUsername() | $user->username |
If you have custom UserInterface implementations, update them:
Before (3.x):
use DH\Auditor\User\UserInterface;
class MyUser implements UserInterface
{
public function getIdentifier(): ?string { return $this->id; }
public function getUsername(): ?string { return $this->name; }
}
After (4.0):
use DH\Auditor\User\UserInterface;
class MyUser implements UserInterface
{
public ?string $identifier { get => $this->id; }
public ?string $username { get => $this->name; }
}
🔡 UTF-8 Conversion Now Opt-In
IMPORTANT
The automatic UTF-8 re-encoding of audit diffs has been removed from the default path.
What Changed
Previously, auditor always called mb_convert_encoding() recursively on the entire diff array before persisting each audit entry. This guaranteed that any non-UTF-8 byte sequence in entity field values would be sanitized before being stored.
This pass now only runs when the utf8_convert option is explicitly enabled.
Who Is Affected
You are affected if your application:
- Uses a database connection that was not explicitly configured as UTF-8, and
- Persists entity fields that may contain non-UTF-8 strings (e.g. data imported from ISO-8859-1 sources, legacy BLOBs, etc.)
Applications running on a modern stack (DBAL 4 + PHP 8.4 + UTF-8 database charset) are not affected — the conversion was already a no-op for them.
How to Fix
Add 'utf8_convert' => true to your DoctrineProvider configuration:
use DH\Auditor\Provider\Doctrine\Configuration;
$configuration = new Configuration([
// ... other options ...
'utf8_convert' => true,
]);
Why the Default Is false
DBAL 4 mandates PHP 8.4+ and enforces UTF-8 database connections. Traversing and re-encoding every diff array on every flush was unnecessary overhead for the vast majority of users. The option is preserved for applications that still process legacy non-UTF-8 data.
🆕 New extra_data Column
Schema Change
IMPORTANT
A new nullable JSON column extra_data has been added to all audit tables. Run the schema update command after upgrading.
php bin/console audit:schema:update --dump-sql # Preview
php bin/console audit:schema:update --force # Apply
Two ways to populate extra_data
Option 1 — Global provider (new in 4.0): set a callable on Configuration once and it runs automatically for every audit entry produced during a flush:
$configuration->setExtraDataProvider(function (): ?array {
return [
'ip' => $this->requestStack->getCurrentRequest()?->getClientIp(),
'role' => $this->security->getUser()?->getRoles(),
];
});
Option 2 — Per-entity listener: LifecycleEvent now exposes $event->entity (the audited object), allowing listeners to add entity-specific context:
#[AsEventListener(event: LifecycleEvent::class, priority: 10)]
final class AuditExtraDataListener
{
public function __invoke(LifecycleEvent $event): void
{
$payload = $event->getPayload();
if ($payload['entity'] === User::class && null !== $event->entity) {
$payload['extra_data'] = json_encode([
'department' => $event->entity->getDepartment(),
], JSON_THROW_ON_ERROR);
$event->setPayload($payload);
}
}
}
The provider runs first; the listener can override or extend its output. See the Extra Data guide for precedence rules, merging strategies, and caveats.
🔢 TransactionType Enum
TIP
Transaction type constants have been replaced by a backed enum for better type safety.
| Before (3.x) | After (4.0) |
|---|---|
Transaction::INSERT | TransactionType::Insert->value |
Transaction::UPDATE | TransactionType::Update->value |
Transaction::REMOVE | TransactionType::Remove->value |
Transaction::ASSOCIATE | TransactionType::Associate->value |
Transaction::DISSOCIATE | TransactionType::Dissociate->value |
Before (3.x):
use DH\Auditor\Model\Transaction;
if ($entry->getType() === Transaction::INSERT) {
// ...
}
After (4.0):
use DH\Auditor\Model\TransactionType;
if ($entry->type === TransactionType::Insert->value) {
// ...
}