<?php
namespace App\models\Logistic\Api\Custom;
use App\models\Logistic\Api\Custom\ClientConfig;
use App\models\Logistic\Api\Custom\Client\BeanStalk;
use App\models\Logistic\Api\Custom\Client\Mq;
use App\models\Logistic\Api\Custom\Client\Ftp;
class ClientFactory{
    /**
     * note:
     * Auther:Yao
     * Date:2022/7/7 11:13
     * @param $clientName
     * @return \App\models\Logistic\Custom\Client\BeanStalk|\App\models\Logistic\Custom\Client\Mq
     * @throws \Exception
     */
    public static function factory($clientName,$config){
        $clientConfig = new ClientConfig();
        $clientConfig->setConfigType($clientName);
        $clientConfig->setConfig($config);
        $config = $clientConfig->getConfig();
        if(empty($config)){
            throw new \Exception("初始化发送参数错误");
        }
        if($clientName=='BeanStalk'){
            return new BeanStalk($clientConfig);
        }
        if($clientName == 'Mq'){
            return new Mq($clientConfig);
        }
        if($clientName == 'Ftp'){
            return new Ftp($clientConfig);
        }
       throw new \Exception("clientName error");
    }


}
