Skip to content

Internals

Tom Anderson edited this page Mar 17, 2016 · 6 revisions

The core classes involved with auditing are registered at bootstrap from the Module.

public function onBootstrap(MvcEvent $e)
{
    $serviceManager = $e->getParam('application')->getServiceManager();
    $serviceManager->get('ZF\Doctrine\Audit\Loader\AuditAutoloader')->register();
    $serviceManager->get('ZF\Doctrine\Audit\Mapping\Driver\AuditDriver')->register();
    $serviceManager->get('ZF\Doctrine\Audit\EventListener\LogRevision')->register();
 }

AuditAutoloader

This class dynamically creates PHP classes for Entities in the audit object manager. Because every entity managed by an object manager needs an object from which to be managed, this class creates those entity classes as needed. Uses a use Zend\Loader\StandardAutoloader.

AuditDriver

This is a driver for Doctrine which is registered at run time to the audit object manager. This driver registers an XML driver for the concrete zf-doctrine-audit classes and registers itself to map the metadata for the entities created by the AuditAutoloader.

LogRevision

The workhorse for auditing. This listens to onFlush and postFlush on the target object manager events and creates the audit record for them. Because of how this listens it cannot exist on the target object manager and this is why zf-doctrine-audit requires a separate object manager.

Audit Object Manager

The audit object manager is no different than a standard object manager. For all intents and purposes the audit object manager simply manages a different set of entities than those being audited. The LogRevision ties them together. This approach provides you with full access to Doctrine for query building and everything else. You could even write event an EventListener for the audit object manager.

For the (Audit Schema)[Audit Schema] all the classes are concrete and no dynamic relations are created. The entity class definitions and XML metadata are included.

ZF\Doctrine\Audit\RevisionEntity\AbstractAudit

This class is used for all AuditAutoloader created classes as an abstract to inherit from.

Factories and Initializers

In order to keep all the audit initializers out of the core service_manager config the classes used in zf-doctrine-audit use a single abstract factory. This abstract factory is in the core service_manager.

There is one Initializer registered in the service_manager: (Revision Comment)[Revision Comment].

Clone this wiki locally