andreas-glaser/dc-event-bundle
最新稳定版本:1.2.0
Composer 安装命令:
composer require andreas-glaser/dc-event-bundle
包简介
Doctrine Custom Event Bundle - This bundle attaches an event handler during preFlush, allowing you to persist, update and remove entities while having access to change sets.
README 文档
README
This bundle attaches an event handler during preFlush, allowing you to persist, update and remove entities while having access to change sets.
Installation
composer require andreas-glaser/dc-event-bundle ^1
Usage
1.) Attach entity event listener
<?php namespace AppBundle\Entity; use AndreasGlaser\DCEventBundle\EventHandler\Annotations\DCEntityEventHandler; use Doctrine\ORM\Mapping as ORM; /** * Article * * @ORM\Table(name="article") * @ORM\Entity(repositoryClass="AppBundle\Repository\ArticleRepository") * @DCEntityEventHandler(class="AppBundle\EEH\ArticleEEH") */ class Article { /** * @var int * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string * * @ORM\Column(name="subject", type="string", length=255) */ private $subject; /** * @var string * * @ORM\Column(name="body", type="text", nullable=true) */ private $body; /** * Get id * * @return int */ public function getId() { return $this->id; } /** * Set subject * * @param string $subject * * @return Article */ public function setSubject($subject) { $this->subject = $subject; return $this; } /** * Get subject * * @return string */ public function getSubject() { return $this->subject; } /** * Set body * * @param string $body * * @return Article */ public function setBody($body) { $this->body = $body; return $this; } /** * Get body * * @return string */ public function getBody() { return $this->body; } }
2.) Create entity event handler
<?php namespace AppBundle\EEH; use AndreasGlaser\DCEventBundle\EventHandler\DCEntityEventHandlerBase; use AndreasGlaser\DCEventBundle\Helper\ChangeSetHelper; use AppBundle\Entity as AppBundleEntity; /** * Class ArticleEEH * * @package AppBundle\EEH */ class ArticleEEH extends DCEntityEventHandlerBase { /** * @var AppBundleEntity\Article */ protected $entity; /** * @return void */ public function prePersist() { // TODO: Implement prePersist() method. } /** * @return void */ public function postPersist() { // TODO: Implement postPersist() method. } /** * @param \AndreasGlaser\DCEventBundle\Helper\ChangeSetHelper $changeSet * * @return void */ public function preUpdate(ChangeSetHelper $changeSet) { // TODO: Implement preUpdate() method. } /** * @return void */ public function postUpdate() { // TODO: Implement postUpdate() method. } /** * @return void */ public function preRemove() { // TODO: Implement preRemove() method. } /** * @return void */ public function postRemove() { // TODO: Implement postRemove() method. } }
统计信息
- 总下载量: 942
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-09-22