decoda / audit
为 CodeIgniter 4 提供轻量级对象日志
0.3
2024-09-10 01:20 UTC
Requires
- php: ^7.4 || ^8.0
- swaggest/json-diff: ^3.11
Requires (Dev)
- codeigniter4/framework: ^4.1
This package is auto-updated.
Last update: 2024-09-10 01:36:57 UTC
README
为 CodeIgniter 4 提供轻量级对象日志
快速开始
- 使用 Composer 安装:
> composer require decoda/audit
- 更新数据库:
> php spark migrate -all
- 设置你的模型
class JobModel extends Model { use \Decoda\Audit\Traits\AuditTrait; protected $afterInsert = ['auditInsert']; protected $beforeUpdate = ['auditBeforeUpdate']; protected $afterUpdate = ['auditAfterUpdate']; protected $afterDelete = ['auditDelete'];
功能
为 CodeIgniter 4 提供现成的对象日志功能
安装
通过 Composer 轻松安装以利用 CodeIgniter 4 的自动加载功能,并始终保持最新状态
> composer require decoda/audit
或者,通过下载源文件并将其添加到 app/Config/Autoload.php
中来手动安装。
一旦下载文件并包含在自动加载中,运行任何库迁移以确保数据库设置正确
> php spark migrate -all
配置(可选)
可以通过扩展其配置文件来更改库的默认行为。将 examples/Audit.php 复制到 app/Config/Audit.php,并按照注释中的说明操作。如果在 app/Config 中找不到配置文件,库将使用其自己的。
使用方法
一旦包含库,所有资源都准备就绪,您只需指定要审计哪些模型和事件。使用 AuditTrait 为您希望跟踪的任何模型添加支持
class JobModel extends Model { use \Decoda\Audit\Traits\AuditTrait;
然后指定您想要审计的事件,通过为这些事件分配相应的审计方法
protected $afterInsert = ['auditInsert']; protected $afterUpdate = ['auditUpdate']; protected $afterDelete = ['auditDelete'];
Audit 库将在 audits
表中为每个事件创建基本日志,例如
| id | source | source_id | user_id | event | summary | created_at |
+----+--------+-----------+---------+--------+----------+---------------------+
| 10 | sites | 27 | 9 | create | 2 rows | 2019-04-05 15:58:40 |
| 11 | jobs | 10 | 9 | update | 5 rows | 2019-04-05 16:01:35 |