PHP code example of jtreminio / entity-audit-bundle

1. Go to this page and download the library: Download jtreminio/entity-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/ */

    

jtreminio / entity-audit-bundle example snippets


use Doctrine\ORM\EntityManager;
use Doctrine\Common\EventManager;
use SimpleThings\EntityAudit\AuditConfiguration;
use SimpleThings\EntityAudit\AuditManager;

$auditconfig = new AuditConfiguration();
$auditconfig->setAuditedEntityClasses(array(
    'SimpleThings\EntityAudit\Tests\ArticleAudit',
    'SimpleThings\EntityAudit\Tests\UserAudit'
));

$auditconfig->setGlobalIgnoreColumns(array(
    'created_at',
    'updated_at'
));

$evm = new EventManager();
$auditManager = new AuditManager($auditconfig);
$auditManager->registerEvents($evm);

$config = new \Doctrine\ORM\Configuration();
// $config ...
$conn = array();
$em = EntityManager::create($conn, $config, $evm);

class DefaultController extends Controller
{
    public function indexAction()
    {
        $auditReader = $this->container->get("simplethings_entityaudit.reader");
    }
}

    $auditReader = $auditManager->createAuditReader($entityManager);

    $articleAudit = $auditReader->find(
        'SimpleThings\EntityAudit\Tests\ArticleAudit',
        $id = 1,
        $rev = 10
    );

    $revisions = $auditReader->findRevisions(
        'SimpleThings\EntityAudit\Tests\ArticleAudit',
        $id = 1
    );

class Revision
{
    public function getRev();
    public function getTimestamp();
    public function getUsername();
}

    $changedEntities = $auditReader->findEntitiesChangedAtRevision( 10 );

class ChangedEntity
{
    public function getClassName();
    public function getId();
    public function getRevisionType();
    public function getEntity();
}

    $revision = $auditReader->getCurrentRevision(
        'SimpleThings\EntityAudit\Tests\ArticleAudit',
        $id = 3
    );

    // Symfony2 Context
    $container->get('simplethings_entityaudit.config')->setCurrentUsername( "beberlei" );

    // Standalone App
    $auditConfig = new \SimpleThings\EntityAudit\AuditConfiguration();
    $auditConfig->setCurrentUsername( "beberlei" );
 bash
$ php composer.phar 
 php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        //...
        new SimpleThings\EntityAudit\SimpleThingsEntityAuditBundle(),
        //...
    );
    return $bundles;
}