src/PHPDish/Bundle/UserBundle/EventListener/UserSubscriber.php
public function postPersist($user, LifecycleEventArgs $event)
    {
        $now = Carbon::now();
        $user->setCreatedAt($now)->setUpdatedAt($now);
        $user->setAvatar($this->avatarGenerator->generate($user->getUsername())->getKey()); //生成临时头像

        $this->eventDispatcher->dispatch(Events::USER_CREATED, new UserEvent($user));
    }
public function postPersist($user, LifecycleEventArgs $event)
    {
        $now = Carbon::now();
        $user->setCreatedAt($now)->setUpdatedAt($now);
        $user->setAvatar($this->avatarGenerator->generate($user->getUsername())->getKey()); //生成临时头像

        $this->eventDispatcher->dispatch(Events::USER_CREATED, new UserEvent($user));
    }
doctrine 事件，数据库写入

@param UserInterface $user
@param LifecycleEventArgs $event