<?php
// +----------------------------------------------------------------------
// | onezan-admin 快速开发的管理平台
// +----------------------------------------------------------------------
// | 官方网址：https://www.onezan.cn
// +----------------------------------------------------------------------
// | onezan团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: 543885307@qq.com
// +----------------------------------------------------------------------
namespace app\listener\user;

use app\event\user\UserRegistered;
use Core\service\queue\QueueDispatcher;


/**
 * User Registered Listener
 * @package app\listener\user
 */
class UserRegisteredListener
{

    /**
     * 处理用户注册事件
     * 将用户注册信息推入消息队列供后续审计处理
     * @param UserRegistered $event 注册事件对象
     * @return void
     */
    public function handle(UserRegistered $event): void
    {
        $this->queue()->dispatch('user.registered.audit', [
            'user_id' => $event->userId,
            'username' => $event->username,
            'phone' => $event->phone,
            'email' => $event->email,
        ], [
            'biz_key' => 'user.registered.audit:' . $event->userId,
        ]);
    }

    /**
     * 获取队列分发器
     * @return QueueDispatcher
     */
    private function queue(): QueueDispatcher
    {
        return app()->make(QueueDispatcher::class);
    }
}