定制 knplabs/rad-doctrine-event 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

knplabs/rad-doctrine-event

最新稳定版本:v2.2.0

Composer 安装命令:

composer require knplabs/rad-doctrine-event

包简介

Access your doctrine events from the Symfony DIC.

README 文档

README

Unfortunately we decided to not maintain this project anymore (see why). If you want to mark another package as a replacement for this one please send an email to hello@knplabs.com.

Rapid Application Development : Doctrine Events

Access to your doctrine events from the Symfony DIC.

Build Status Scrutinizer Code Quality Latest Stable Version Total Downloads Latest Unstable Version License

Official maintainers:

Installation

composer require knplabs/rad-doctrine-event ~2.1

And with Symfony:

class AppKernel
{
    function registerBundles()
    {
        $bundles = array(
            //...
            new Knp\Rad\DoctrineEvent\Bundle\DoctrineEventBundle(),
            //...
        );

        //...

        return $bundles;
    }
}

Use

Context

Let's say you have the following entity:

namespace App\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class User
{
    //...
}

Before

In order to plug doctrine events for that entity, we usually do:

namespace App\EventListener;

use App\Entity\User;
use Doctrine\ORM\Event\LifecycleEventArgs;

class UserListener
{
    public function prePersist(LifecycleEventArgs $args)
    {
        $entity = $args->getEntity();

        if (false === $entity instanceof User) {
            return;
        }

        // Some stuff
    }
}
#services.yml
services:
    app.event_listener.user_listener:
        class: App\EventListener\UserListener
        tags:
            - { name: doctrine.event_listener, event: pre_persist, method: prePersist }

After

But with the KnpRadDoctrineEvent you will need:

namespace App\EventListener;

use Knp\Rad\DoctrineEvent\Event\DoctrineEvent;

class UserListener
{
    public function prePersist(DoctrineEvent $event)
    {
        $entity = $event->getEntity();

        // Some stuff
    }
}
#services.yml
services:
    app.event_listener.user_listener:
        class: App\EventListener\UserListener
        tags:
            - { name: kernel.event_listener, event: app.entity.user.pre_persist, method: prePersist }

Inheritance

Context

Let's say you have an entity extending another entity:

namespace App\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="type", type="string")
 * @ORM\DiscriminatorMap({"page" = "App\Entity\Customer"})
 */
class User
{
    //...
}
namespace App\Entity;

use App\Entity\User;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class Customer extends User
{
    //...
}

Events

The parent entity events are dispatched just before the children entities:

For First event Second Event
pre_persist app.entity.user.pre_persist app.entity.customer.pre_persist
post_update app.entity.user.pre_update app.entity.customer.pre_update
...

Terminate

Each post (post_persist, post_update, post_remove, post_load) event is also redispatched during the kernel.terminate event.

Event Terminate event
app.entity.user.post_persist app.entity.user.post_persist_terminate
app.entity.user.post_update app.entity.user.post_update_terminate
app.entity.user.post_remove app.entity.user.post_remove_terminate
app.entity.user.post_load app.entity.user.post_load_terminate

Configuration

You can restrict event re-dispatching to specific entities.

You just have to follow this configuration:

knp_rad_doctrine_event:
    entities:
        - MyBundle\Entity\User

Then events will be dispatched only for the entity MyBundle\Entity\User.

knplabs/rad-doctrine-event 适用场景与选型建议

knplabs/rad-doctrine-event 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 36.8k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2014 年 12 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 knplabs/rad-doctrine-event 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 knplabs/rad-doctrine-event 我们能提供哪些服务?
定制开发 / 二次开发

基于 knplabs/rad-doctrine-event 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 36.8k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 19
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 28
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-12-23