1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the wannanbigpig/alipay-sdk-php. |
4
|
|
|
* |
5
|
|
|
* (c) wannanbigpig <[email protected]> |
6
|
|
|
* |
7
|
|
|
* This source file is subject to the MIT license that is bundled |
8
|
|
|
* with this source code in the file LICENSE. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace EasyAlipay; |
12
|
|
|
|
13
|
|
|
use EasyAlipay\Kernel\Exceptions\ApplicationException; |
14
|
|
|
use WannanBigPig\Supports\Str; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class Alipay |
18
|
|
|
* |
19
|
|
|
* @method static \EasyAlipay\Payment\Application payment(array $config = []) |
20
|
|
|
* @method static \EasyAlipay\Tripartite\Application tripartite(array $config = []) |
21
|
|
|
* @method static \EasyAlipay\MiniProgram\Application miniProgram(array $config = []) |
22
|
|
|
* @method static \EasyAlipay\BaseService\Application baseService(array $config = []) |
23
|
|
|
* |
24
|
|
|
* @author liuml <[email protected]> |
25
|
|
|
* @DateTime 2019-07-26 18:18 |
26
|
|
|
*/ |
27
|
|
|
class Alipay |
28
|
|
|
{ |
29
|
|
|
protected static $config = []; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* make. |
33
|
|
|
* |
34
|
|
|
* @param string $name |
35
|
|
|
* @param array $config |
36
|
|
|
* |
37
|
|
|
* @return mixed |
38
|
|
|
* |
39
|
|
|
* @throws \EasyAlipay\Kernel\Exceptions\ApplicationException |
40
|
|
|
*/ |
41
|
192 |
|
public static function make(string $name, array $config = []) |
42
|
|
|
{ |
43
|
192 |
|
$namespace = Str::studly($name); |
44
|
192 |
|
$application = __NAMESPACE__."\\{$namespace}\\Application"; |
45
|
|
|
|
46
|
192 |
|
if (class_exists($application)) { |
47
|
192 |
|
$config = array_replace_recursive(self::$config, $config); |
48
|
|
|
|
49
|
|
|
// Instantiation application |
50
|
192 |
|
return new $application($config); |
51
|
|
|
} |
52
|
2 |
|
throw new ApplicationException("Application [{$name}] does not exist"); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Dynamically pass methods to the application. |
57
|
|
|
* |
58
|
|
|
* @param $name |
59
|
|
|
* @param $arguments |
60
|
|
|
* |
61
|
|
|
* @return mixed |
62
|
|
|
* |
63
|
|
|
* @throws \EasyAlipay\Kernel\Exceptions\ApplicationException |
64
|
|
|
*/ |
65
|
192 |
|
public static function __callStatic($name, $arguments) |
66
|
|
|
{ |
67
|
192 |
|
return self::make($name, ...$arguments); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @static initialize. |
72
|
|
|
* |
73
|
|
|
* @param array $config |
74
|
|
|
* |
75
|
|
|
* @return \EasyAlipay\Alipay |
76
|
|
|
*/ |
77
|
2 |
|
public static function initialize(array $config): self |
78
|
|
|
{ |
79
|
2 |
|
self::$config = $config; |
80
|
|
|
|
81
|
2 |
|
return new static(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* __call. |
86
|
|
|
* |
87
|
|
|
* @param $name |
88
|
|
|
* @param $arguments |
89
|
|
|
* |
90
|
|
|
* @return mixed |
91
|
|
|
* |
92
|
|
|
* @throws \EasyAlipay\Kernel\Exceptions\ApplicationException |
93
|
|
|
*/ |
94
|
2 |
|
public function __call($name, $arguments) |
95
|
|
|
{ |
96
|
2 |
|
return self::make($name, ...$arguments); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|