Skip to main content
Version: 4.x

DoctrineProvider

The default provider for auditing Doctrine ORM entities

The DoctrineProvider is the default and primary provider shipped with auditor. It provides both auditing and storage capabilities for Doctrine ORM entities.

🔍 Overview

The DoctrineProvider:

  • 📝 Tracks entity changes - Inserts, updates, and deletes
  • 🔗 Tracks relationships - Many-to-many associations and dissociations
  • 💾 Persists audit logs - Stores audits in dedicated audit tables
  • 🔄 Transactional integrity - Audit entries are part of the same transaction as your changes

✨ Key Features

Automatic Change Detection

The provider hooks into Doctrine's event system to automatically detect:

  • Insertions - New entities being persisted
  • Updates - Changes to existing entities with full diff
  • Deletions - Entities being removed
  • Associations - Relationships being created
  • Dissociations - Relationships being removed

Audit Table Structure

For each audited entity, a corresponding audit table is created:

ColumnTypeDescription
idintegerAuto-increment primary key
typestring(10)Action type (insert/update/remove/etc)
object_idstring(255)ID of the audited entity
discriminatorstring(255)Entity class (for inheritance)
transaction_hashstring(40)Hash grouping related changes
diffsjson/textThe actual changes (JSON)
blame_idstring(255)User identifier
blame_userstring(255)Username
blame_user_fqdnstring(255)User class name
blame_user_firewallstring(100)Firewall name
ipstring(45)Client IP address
created_atdatetimeWhen the audit was created

Action Types

TypeDescription
insertA new entity was created
updateAn existing entity was modified
removeAn entity was deleted
associateA many-to-many relationship was created
dissociateA many-to-many relationship was removed

🏗️ Architecture

🗄️ Supported Databases

DatabaseSupportNotes
MySQLFull support with JSON column type
MariaDBFull support with JSON column type
PostgreSQLFull support with JSON column type
SQLiteJSON stored as TEXT

⚠️ Limitations

CAUTION

Important limitations to be aware of:

  1. Composite primary keys are not supported
  2. DQL/SQL direct queries are not tracked - Only changes through EntityManager
  3. Bulk operations are not tracked - Use EntityManager::flush() after each entity

📚 Sections

🚀 Basic Usage

<?php

use DH\Auditor\Provider\Doctrine\Configuration;
use DH\Auditor\Provider\Doctrine\DoctrineProvider;
use DH\Auditor\Provider\Doctrine\Service\AuditingService;
use DH\Auditor\Provider\Doctrine\Service\StorageService;

// Create configuration
$configuration = new Configuration([
'table_suffix' => '_audit',
'entities' => [
App\Entity\User::class => ['enabled' => true],
App\Entity\Post::class => ['enabled' => true],
],
]);

// Create provider
$provider = new DoctrineProvider($configuration);

// Register services
$provider->registerAuditingService(new AuditingService('default', $entityManager));
$provider->registerStorageService(new StorageService('default', $entityManager));

// Register with auditor
$auditor->registerProvider($provider);

Next Steps