PHP code example of gtt / doctrine-auditable-bundle

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

    

gtt / doctrine-auditable-bundle example snippets


public function registerBundles()
{
    $bundles = array(
        ...
        new Gtt\Bundle\DoctrineAuditableBundle\DoctrineAuditableBundle(),
    );
    ...
}



use Gtt\Bundle\DoctrineAuditableBundle\Mapping\Annotation as Auditable;

/**
 * My entity
 */
 #[ORM\Entity]
 #[ORM\Table(name: 'entity')]
 #[Auditable\Entity]
class Entity
{
     #[ORM\Column(name: 'assigned_user', type: 'string', length: 255)]
     #[Auditable\Property]
    protected string $assignedUser;
    
    ...
}



use Doctrine\ORM\EntityManagerInterface;
use Gtt\Bundle\DoctrineAuditableBundle as Auditable;

class PayloadService {
    private Auditable\Log\Store $auditable;
    
    private EntityManagerInterface $entityManager;

    /**
     * Operate!
     */
    public function payloadMethod(YourDomain\Entity $entity): void 
    {
        // 1. change some property that supposed to be logged to changelog
        $entity->updateProperty();  // ... just dummy example
        
        // 2. describe this change
        $this->auditable->describe($entity, 'Change description');
      
        // 3. perform update 
        $this->entityManager->flush();
    }
}