Issues (54)

src/Factory.php (1 issue)

Labels
Severity
1
<?php
2
namespace tinymeng\Chinaums;
3
4
define('CHINAUMS_ROOT_PATH', dirname(__DIR__));
5
use Exception;
6
use tinymeng\tools\StringTool;
7
8
/**
9
 * @method static \tinymeng\Chinaums\Provider\Unionpay Unionpay(null|array $config) 网银支付
10
 * @method static \tinymeng\Chinaums\Provider\Alipay Alipay(null|array $config) 支付宝支付
11
 * @method static \tinymeng\Chinaums\Provider\Wechat Wechat(null|array $config) 微信支付
12
 * @method static \tinymeng\Chinaums\Provider\Contract Contract(null|array $config) 自助签约
13
 */
14
class Factory
15
{
16
17
    /**
18
     * @var array $config
19
     */
20
    protected static $config;
21
22
    /**
23
     * @param $gateway
24
     * @param null|array $config
25
     * @return mixed
26
     * @throws Exception
27
     */
28
    public static function init($gateway, $config=[])
29
    {
30
        $gateway = StringTool::uFirst($gateway);
31
        $class = __NAMESPACE__ . '\\Provider\\' . $gateway;
32
        if (class_exists($class)) {
33
            if(empty(self::$config)) self::config($config);
34
            $objcet = new $class(self::$config);
35
            return $objcet;
36
        } else {
37
            throw new Exception("err:{$class}类不存在");
38
        }
39
    }
40
41
    /**
42
     * @param $config
43
     * @return false|void
44
     */
45
    public static function config($config)
46
    {
47
        $configFile = CHINAUMS_ROOT_PATH."/config/chinaums.php";
48
        if (!file_exists($configFile)) {
49
            return false;
50
        }
51
        $baseConfig = require $configFile;
52
        self::$config = array_replace_recursive($baseConfig,$config);
53
    }
54
55
    /**
56
     * @param $gateway
57
     * @param $config
58
     * @return mixed
59
     * @throws Exception
60
     */
61
    public static function __callStatic($gateway, $config=[])
62
    {
63
        return self::init($gateway, ...$config);
0 ignored issues
show
$config is expanded, but the parameter $config of tinymeng\Chinaums\Factory::init() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

63
        return self::init($gateway, /** @scrutinizer ignore-type */ ...$config);
Loading history...
64
    }
65
}
66