承接 atournayre/entities-events-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

atournayre/entities-events-bundle

Composer 安装命令:

composer require atournayre/entities-events-bundle

包简介

This bundle provides a way to dispatch events when entities are created, updated or deleted using Doctrine ORM events and Symfony EventDispatcher.

README 文档

README

This bundle provides a way to dispatch events when entities are created, updated or deleted using Doctrine ORM events and Symfony EventDispatcher.

Requirements

Symfony ^6 || ^7

PHP >=8.2

Install

Use Composer to install the package:

Composer

composer require atournayre/entities-events-bundle

Register bundle

// config/bundles.php

return [
    // ...
    Atournayre\Bundle\EntitiesEventsBundle\AtournayreEntitiesEventsBundle::class => ['all' => true],
    // ...
]

Install listeners

php bin/console atournayre:entities-events:generate-listeners

Usage example

Update your entity

use Atournayre\Bundle\EntitiesEventsBundle\Collection\EventCollection;
use Atournayre\Bundle\EntitiesEventsBundle\Contracts\HasEventsInterface;

// Implements HasEventsInterface
class YourEntity implements HasEventsInterface
{
  // Use EventsTrait to implement HasEventsInterface
  use EventsTrait;
  
  public function __construct()
  {
    // Initialize the collection of events
    $this->eventCollection = new EventCollection();
  }
  
  public function doSomething(): void
  {
    // Do something here
    // Then dispatch an event
    $this->addEvent(new YourEvent($this));
  }
}

Create an event

use Symfony\Contracts\EventDispatcher\Event;

class YourEvent extends Event
{
  public function __construct(
    public readonly YourEntity $entity
  ) {}
}

Handle an event

use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

#[AsEventListener]
class YourEventListener
{
  public function __invoke(YourEvent $event): void
  {
    // Do something here
  }
}

That's all, the bundle will do the rest.

Contribute

Contributions to the package are always welcome!

License

All contents of this package are licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2023-11-05