1. Go to this page and download the library: Download rasuvaeff/yii3-audit-log 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/ */
rasuvaeff / yii3-audit-log example snippets
use Psr\Clock\ClockInterface;
use Rasuvaeff\Yii3AuditLog\AuditWriter;
return [
AuditWriter::class => MyAuditWriter::class,
ClockInterface::class => MyClock::class,
];
// config/common/di/audit-log.php
use Rasuvaeff\Yii3AuditLog\AuditEventIdGeneratorInterface;
use Rasuvaeff\Yii3AuditLog\Uuid7IdGenerator;
return [
AuditEventIdGeneratorInterface::class => Uuid7IdGenerator::class,
];
use Rasuvaeff\Yii3AuditLog\AuditActor;
use Rasuvaeff\Yii3AuditLog\AuditChangeSet;
use Rasuvaeff\Yii3AuditLog\AuditLogger;
use Rasuvaeff\Yii3AuditLog\AuditSubject;
use Rasuvaeff\Yii3AuditLog\InMemoryAuditWriter;
$logger = new AuditLogger(writer: $writer, clock: $clock);
$logger->logChange(
actor: AuditActor::user(id: $userId, name: 'John'),
subject: AuditSubject::of(type: 'order', id: (string) $orderId),
changes: AuditChangeSet::fromArrays(
old: ['status' => 'new', 'total' => 0],
new: ['status' => 'paid', 'total' => 99.95],
),
);
use Rasuvaeff\Yii3AuditLog\AuditEvent;
use Rasuvaeff\Yii3AuditLog\AuditWriter;
final readonly class DbAuditWriter implements AuditWriter
{
public function write(AuditEvent $event): void
{
// INSERT INTO audit_log ...
// $event->getId(), $event->getActor(), $event->getAction(),
// $event->getSubject(), $event->getChangeSet(), $event->getOccurredAt()
}
}
use Rasuvaeff\Yii3AuditLog\AuditLogger;
use Rasuvaeff\Yii3AuditLog\SensitiveValueMasker;
$logger = new AuditLogger(
writer: $writer,
clock: $clock,
masker: new SensitiveValueMasker(), // masks password, secret, token, api_key, credit_card
);
// Custom sensitive keys:
$masker = new SensitiveValueMasker(sensitiveKeys: ['ssn', 'pin', 'password']);