Total Complexity | 6 |
Total Lines | 50 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
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) |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param $gateway |
||
57 | * @param $config |
||
58 | * @return mixed |
||
59 | * @throws Exception |
||
60 | */ |
||
61 | public static function __callStatic($gateway, $config=[]) |
||
66 |