Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Auditor Laravel Package

damienharper/auditor

View on GitHub
Deep Wiki
Context7

Configuration Reference

All configuration options available in auditor

This section covers all configuration options available in auditor.

⚙️ Auditor Configuration

The main Configuration class accepts the following options:

<?php

use DH\Auditor\Configuration;

$configuration = new Configuration([
    'enabled' => true,
    'timezone' => 'UTC',
    'user_provider' => null,
    'security_provider' => null,
    'role_checker' => null,
]);

Options Reference

Option Type Default Description
enabled bool true Enable or disable auditing globally
timezone string 'UTC' Timezone used for audit timestamps
user_provider callable|null null Callback that returns the current user
security_provider callable|null null Callback that returns security context info
role_checker callable|null null Callback that checks if user can view entity audits

🔧 Configuration Methods

Enable/Disable Auditing

// Disable auditing
$configuration->disable();

// Re-enable auditing
$configuration->enable();

// Check if auditing is enabled
if ($configuration->isEnabled()) {
    // ...
}

Get Timezone

$timezone = $configuration->getTimezone();

👤 User Provider

The user provider is a callable that returns information about the current user. This is used to record who made each change.

use DH\Auditor\User\User;

$configuration->setUserProvider(function (): ?User {
    // Return null if no user is authenticated
    $currentUser = $this->security->getUser();
    
    if (null === $currentUser) {
        return null;
    }
    
    return new User(
        (string) $currentUser->getId(),  // User identifier
        $currentUser->getUsername()       // Username for display
    );
});

The User class implements UserInterface:

namespace DH\Auditor\User;

interface UserInterface
{
    public function getIdentifier(): ?string;
    public function getUsername(): ?string;
}

See User Provider Configuration for more details.

🔐 Security Provider

The security provider returns contextual security information to be stored with audit entries:

$configuration->setSecurityProvider(function (): array {
    return [
        'client_ip' => $_SERVER['REMOTE_ADDR'] ?? null,
        'user_fqdn' => $this->security->getUser()?::class,
        'user_firewall' => $this->getFirewallName(),
    ];
});

See Security Provider Configuration for more details.

🛡️ Role Checker

The role checker determines whether a user can view audits for a specific entity:

$configuration->setRoleChecker(function (string $entity, string $scope): bool {
    // $entity is the FQCN of the audited entity
    // $scope is the action (e.g., 'view')
    
    // Example: Only admins can view User audits
    if ($entity === User::class) {
        return $this->security->isGranted('ROLE_ADMIN');
    }
    
    // Allow everyone to view other audits
    return true;
});

See Role Checker Configuration for more details.

🗄️ DoctrineProvider Configuration

The DoctrineProvider has its own configuration. See DoctrineProvider Configuration for details.

📝 Configuration Summary

<?php

use DH\Auditor\Auditor;
use DH\Auditor\Configuration;
use DH\Auditor\User\User;
use Symfony\Component\EventDispatcher\EventDispatcher;

$configuration = new Configuration([
    'enabled' => true,
    'timezone' => 'Europe/Paris',
]);

// Set user provider
$configuration->setUserProvider(function (): ?User {
    $user = $securityContext->getUser();
    if (null === $user) {
        return null;
    }
    return new User((string) $user->getId(), $user->getUsername());
});

// Set security provider
$configuration->setSecurityProvider(function (): array {
    return [
        'client_ip' => $_SERVER['REMOTE_ADDR'] ?? null,
    ];
});

// Set role checker
$configuration->setRoleChecker(function (string $entity, string $scope): bool {
    return $this->authorizationChecker->isGranted('ROLE_AUDIT_VIEWER');
});

$auditor = new Auditor($configuration, new EventDispatcher());

Next Steps

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui