PHP code example of jul6art / audit-bundle

1. Go to this page and download the library: Download jul6art/audit-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jul6art / audit-bundle example snippets


namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Jul6Art\CoreBundle\Attribute\Purgeable;
use Jul6Art\CoreBundle\Entity\Traits\IdTrait;

#[ORM\Entity(repositoryClass: AuditLogRepository::class)]
#[ORM\Table(name: 'audit_log')]
#[ORM\Index(columns: ['action'])]
#[ORM\Index(columns: ['created_at'])]
#[Purgeable(field: 'createdAt', interval: '-3 months')]
class AuditLog extends \Jul6Art\AuditBundle\Entity\AuditLog
{
    use IdTrait;
}

use Jul6Art\AuditBundle\Attribute\Auditable;

#[ORM\Entity]
#[Auditable]
class Invoice { … }

#[Auditable(onUpdate: false)]                              // creations and deletions only
#[Auditable(ignoredFields: ['updatedAt', 'viewCount'])]    // noise kept out of the diff
class Draft { … }

$this->auditLogger->log('invoice.sent', $organizationId, $actorId, 'Invoice', $invoice->getId(), ['channel' => 'email']);

$this->auditLogger->startBatch();
try {
    $this->provisionEverything();
} finally {
    $this->auditLogger->endBatch();   // one persist + one flush, here
}

$this->auditLogger->startBatch();
try {
    $this->stateMachine->apply($order, 'ship');
    $this->entityManager->flush();    // the listener writes here…
} finally {
    $this->auditLogger->endBatch();   // …and the row lands here
}

$this->auditableListener->startSkip();
try {
    $this->provisionForPlan($plan);   // hundreds of audited entities
} finally {
    $this->auditableListener->endSkip();
}

#[Purgeable(field: 'createdAt', interval: '%app.audit_retention%')]