adt/doctrine-loggable

Doctrine实体变更的日志记录

v1.6.1 2024-08-30 10:59 UTC

README

安装

  1. 通过composer安装

    composer require adt/doctrine-loggable
  2. 在config.neon中注册此扩展

    extensions:
        - Adt\DoctrineLoggable\DI\LoggableExtension
  3. 进行数据库迁移

  4. 给需要记录日志的实体添加注解

<?php

use Doctrine\ORM\Mapping as ORM;
use Adt\DoctrineLoggable\Annotations as ADA;
	
/**
 * @ORM\Entity
 * @ADA\LoggableEntity
 */
class User
{

	/**
	 * @ORM\Column(type="string", nullable=true)
	 * @ADA\LoggableProperty(label="entity.user.firstname")
	 */
	protected $firstname;

	/**
	 * @ORM\ManyToMany(targetEntity="Role", inversedBy="users")
	 * @ADA\LoggableProperty(logEntity=false, label="entity.user.roles")
	 */
	protected $roles;
	
}

/**
 * @ORM\Entity
 * @ADA\LoggableIdentification(fields={"name"})
 */
class Role
{

	/**
	 * @ORM\Column(type="string")
	 */
	protected $name;

	/**
	 * @ORM\ManyToMany(targetEntity="User", mappedBy="roles")
	 */
	protected $users;

}