定制 faustvik/yii2-audit-log 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

faustvik/yii2-audit-log

最新稳定版本:v1.0.2

Composer 安装命令:

composer require faustvik/yii2-audit-log

包简介

Audit log package for Yii2 with framework-agnostic core

README 文档

README

Audit logging package for Yii2 applications with framework-agnostic core.

Features

  • Automatic logging - INSERT, UPDATE, DELETE operations via Behavior
  • Events - Before/After log events for customization
  • Query builder - Advanced filtering with AuditLogQuery
  • Ready-to-use widgets - Display change history with filters
  • Framework-agnostic core - Can be used with any PHP framework
  • Yii2 integration - Behavior, Widgets, Migrations out of the box

Requirements

  • PHP 8.2+
  • Yii2 2.0.51+

Quick Start

1. Install via Composer

composer require faustvik/yii2-audit-log

2. Add Behavior to Model

use FaustVik\AuditLog\Yii2\Integration\AuditLogBehavior;

class User extends ActiveRecord
{
    public function behaviors(): array
    {
        return [
            'auditLog' => [
                'class' => AuditLogBehavior::class,
                'excludeAttributes' => ['hash_password', 'auth_key'],
            ],
        ];
    }
}

3. Display in View

<?= \FaustVik\AuditLog\Yii2\Integration\AuditLogFilterWidget::widget([
    'model' => $user,
    'limit' => 50,
    'title' => 'Change History',
]) ?>

Documentation

Structure

src/
├── Core/                    # Framework-agnostic core
│   ├── Contracts/           # Interfaces
│   ├── DTO/                 # Data Transfer Objects
│   ├── Enums/               # Enumerations
│   ├── Events/              # BeforeLogEvent, AfterLogEvent
│   ├── Exceptions/          # Exceptions
│   ├── Query/               # AuditLogQuery
│   └── Services/            # AuditLogger
│
└── Yii2/                    # Yii2 integration
    ├── Adapter/             # Adapters for Yii2
    ├── Integration/         # Behavior, Widgets
    └── Migrations/          # Migration base classes

Example Usage

Logging with Events

// In bootstrap.php
Yii::$app->on(
    \FaustVik\AuditLog\Core\Events\BeforeLogEvent::class,
    function (\FaustVik\AuditLog\Core\Events\BeforeLogEvent $event) {
        // Cancel logging for specific operations
        if ($event->entityClass === User::class && $event->operation->value === 'DELETE') {
            $event->stopPropagation();
        }
    }
);

Query Logs

use FaustVik\AuditLog\Core\Query\AuditLogQuery;
use FaustVik\AuditLog\Core\Contracts\AuditStorageInterface;

$storage = Yii::createObject(AuditStorageInterface::class);

$logs = (new AuditLogQuery($storage))
    ->forEntity(User::class, $userId)
    ->operation(\FaustVik\AuditLog\Core\Enums\Operation::Update)
    ->dateRange('2025-01-01', '2025-12-31')
    ->limit(50)
    ->all();

License

MIT

Authors

  • FaustVik

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固