1. Go to this page and download the library: Download th3mouk/audit-trail-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/ */
use Th3Mouk\AuditTrail\Attribute\AuditLabel;
use Th3Mouk\AuditTrail\Attribute\AuditScope;
use Th3Mouk\AuditTrail\Attribute\Auditable;
#[ORM\Entity]
#[Auditable(type: 'membership')]
#[AuditScope(root: Organization::class, via: 'organization')]
class OrganizationMembership
{
// Snapshotted onto every entry that names this row, so the trail stays readable
// once the row is gone. A property is the safe form: a label *method* runs inside
// the flush, where reading an unloaded association would cost a query.
#[AuditLabel]
private string $summary;
// ...
}
use Th3Mouk\AuditTrail\AuditLoggerInterface;
use Th3Mouk\AuditTrail\Model\AuditScopeRef;
$this->audit->deleted(
OrganizationMembership::class,
4217,
['role' => 'Manager', 'user' => 'Jean Dupont'],
'Manager — Jean Dupont',
AuditScopeRef::of('organization', 31, 'Acme'),
['origin' => 'bulk-revoke'],
);
$this->entityManager->flush();
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
use Th3Mouk\AuditTrail\Actor\ActorResolverInterface;
use Th3Mouk\AuditTrail\Model\Actor;
#[AutoconfigureTag('audit_trail.actor_resolver', ['priority' => 100])]
final readonly class ApiKeyActorResolver implements ActorResolverInterface
{
public function __construct(private RequestStack $requests)
{
}
public function resolve(): ?Actor
{
$key = $this->requests->getCurrentRequest()?->headers->get('X-Api-Key');
return null === $key ? null : Actor::of($key, 'api_key', 'Integration key');
}
}
// config/packages/audit_trail.php
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $container): void {
$container->extension('audit_trail', [
'bridges' => ['api_platform' => [
'enabled' => true,
'access' => [
// Any one grant is enough. A mapping adds a subject, for permissions anchored on a
// resource: ['attribute' => 'view', 'subject' => 'audit-logs']. Or use 'expression'
// for a raw one, or 'public' => true to opt out loudly.
'grants' => ['show audit'],
],
]],
]);
};
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.