Event.php 1009 字节
<?php

namespace Event;

/**
 * 事件
 * @author:dc
 * @time 2024/9/30 16:33
 * Class Event
 * @package Event
 */
class Event {

    /**
     * 同步
     * @var array
     */
    protected static $alias = [
        // 列表同步成功后
        'mail_sync_list'  =>  [
            SyncMail::class,
            MailBlack::class
        ],

    ];


    /**
     * @param $name
     * @param mixed ...$params
     * @throws \Exception
     * @author:dc
     * @time 2024/9/30 16:55
     */
    public static function call($name, ...$params){
        // 是否已配置
        if(isset(self::$alias[$name])){
            array_map(function ($v) use ($params){
                new $v(...$params);
            },
                is_array(self::$alias[$name])? self::$alias[$name] : [is_array(self::$alias[$name])]
            );
        }else if (class_exists($name)){
            new $name(...$params);
        }else{
            throw new \Exception('event '.$name.' not found');
        }

    }


}