ruspanzer / loggable-bundle
Doctrine 简单可记录实体
1.3.0
2019-10-25 13:14 UTC
Requires
- php: >=7.1
- doctrine/doctrine-bundle: ^1.11
- doctrine/orm: ^2.5
- symfony/event-dispatcher: ^4.3
- symfony/security-bundle: ^4.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.15
- phpstan/phpstan: ^0.11.19
README
简单实体可记录包
如何使用
- 安装包
composer require ruspanzer/loggable-bundle
- 为您的实体实现
Ruspanzer\LoggableBundle\Entity\Interfaces\LoggableInterface
- 如果您需要在两个可记录实体之间设置关系,请在相关实体中使用
getRelatedLogEntities
。此方法必须返回一个LoggableInterface
实体数组。这将允许在搜索主实体时搜索相关日志 - 使用仓库方法 getByObject() 查找日志。或者您也可以编写带有分页和其他酷炫功能的搜索实现
示例
class Place implements LoggableInterface
{
/**
* @ORM\Id()
*/
private $id;
/**
* @ORM\OneToOne(targetEntity="Address")
*/
private $address;
public function getId()
{
return $this->id;
}
public function getRelatedLogEntities()
{
return [];
}
}
class Address implements LoggableInterface
{
/**
* @ORM\Id()
*/
private $id;
/**
* @ORM\OneToOne(targetEntity="Place")
* @ORM\JoinColumn(name="place_id")
*/
private $place;
public function getId()
{
return $this->id;
}
public function getPlace()
{
return $this->place;
}
public function getRelatedLogEntities()
{
return [
$this->getPlace();
];
}
}
如果您将通过位置搜索日志,则将返回地址日志