7
7
8
8
class Config
9
9
{
10
- protected $ appID ;
10
+ /**
11
+ * @var string app区分
12
+ */
13
+ private $ appSource = 'default ' ;
11
14
12
- protected $ appCertificate ;
15
+ /**
16
+ * @var AppConfig[] app 证书
17
+ */
18
+ private $ appKeyArray = [];
13
19
20
+ /**
21
+ * @var string token版本
22
+ */
14
23
protected $ version = "006 " ;
15
24
16
25
/**
17
- * @var Carbon
26
+ * @var string api管理key
18
27
*/
19
- public $ date ;
28
+ protected $ customerKey ;
20
29
30
+ /**
31
+ * @var string api管理密钥
32
+ */
33
+ protected $ customerSecret ;
34
+
35
+ /**
36
+ * @var int api请求超时时间
37
+ */
21
38
protected $ timeOut = 2 ;
22
39
40
+ /**
41
+ * @var int api请求重试次数
42
+ */
43
+ protected $ retry = 1 ;
44
+
45
+ /**
46
+ * @var null guzzle请求handler
47
+ */
23
48
protected $ handler ;
24
49
25
- protected $ retry = 1 ;
26
50
27
- public function __construct (string $ appID = '' , string $ appCertificate = '' )
51
+ public function __construct (string $ appID = '' , string $ appCertificate = '' , string $ customerKey = '' , string $ customerSecret = '' )
28
52
{
29
- $ this ->appID = $ appID ;
30
- $ this ->appCertificate = $ appCertificate ;
53
+ $ appConfig = new AppConfig ();
54
+ if ($ appID || $ appCertificate ) {
55
+ $ appConfig ->setAppID ($ appID );
56
+ $ appConfig ->setAppCertificate ($ appCertificate );
57
+ $ this ->appKeyArray [$ this ->appSource ] = $ appConfig ;
58
+ }
59
+ $ this ->customerKey = $ customerKey ;
60
+ $ this ->customerSecret = $ customerSecret ;
31
61
}
32
62
33
63
/**
34
64
* @throws AgoraException
35
65
*/
36
66
public function checkConfig ()
37
67
{
38
- if (! $ this ->appID ) {
68
+ if (! $ this ->getAppID () ) {
39
69
throw new AgoraException ("appID check failed, should be a non-empty string " );
40
70
}
41
- if (! $ this ->appCertificate ) {
71
+ if (! $ this ->getAppCertificate () ) {
42
72
throw new AgoraException ("appCertificate check failed, should be a non-empty string " );
43
73
}
44
74
}
@@ -48,35 +78,23 @@ public function checkConfig()
48
78
*/
49
79
public function getAppID (): string
50
80
{
51
- return $ this ->appID ;
81
+ return $ this ->appKeyArray [ $ this -> appSource ]-> getAppID () ;
52
82
}
53
83
54
84
/**
55
85
* @return string
56
86
*/
57
87
public function getAppCertificate (): string
58
88
{
59
- return $ this ->appCertificate ;
89
+ return $ this ->appKeyArray [ $ this -> appSource ]-> getAppCertificate () ;
60
90
}
61
91
62
92
/**
63
- * @param string $appID
64
- * @return Config
65
- */
66
- public function setAppID (string $ appID ): Config
67
- {
68
- $ this ->appID = $ appID ;
69
- return $ this ;
70
- }
71
-
72
- /**
73
- * @param string $appCertificate
74
- * @return Config
93
+ * @return string
75
94
*/
76
- public function setAppCertificate ( string $ appCertificate ): Config
95
+ public function getVersion ( ): string
77
96
{
78
- $ this ->appCertificate = $ appCertificate ;
79
- return $ this ;
97
+ return $ this ->version ;
80
98
}
81
99
82
100
/**
@@ -89,34 +107,39 @@ public function setVersion(string $version): Config
89
107
return $ this ;
90
108
}
91
109
92
-
93
-
94
110
/**
95
111
* @return string
96
112
*/
97
- public function getVersion (): string
98
- {
99
- return $ this ->version ;
100
- }
101
-
102
- public function getVersionLen (): int
113
+ public function getCustomerKey (): string
103
114
{
104
- return strlen ( $ this ->version ) ;
115
+ return $ this ->customerKey ;
105
116
}
106
117
107
- public function getAppIdLen (): int
118
+ /**
119
+ * @param string $customerKey
120
+ * @return Config
121
+ */
122
+ public function setCustomerKey (string $ customerKey ): Config
108
123
{
109
- return strlen ($ this ->appID );
124
+ $ this ->customerKey = $ customerKey ;
125
+ return $ this ;
110
126
}
111
127
112
- public function getHandler ()
128
+ /**
129
+ * @return string
130
+ */
131
+ public function getCustomerSecret (): string
113
132
{
114
- return $ this ->handler ;
133
+ return $ this ->customerSecret ;
115
134
}
116
135
117
- public function setHandler (?callable $ handler )
136
+ /**
137
+ * @param string $customerSecret
138
+ * @return Config
139
+ */
140
+ public function setCustomerSecret (string $ customerSecret ): Config
118
141
{
119
- $ this ->handler = $ handler ;
142
+ $ this ->customerSecret = $ customerSecret ;
120
143
return $ this ;
121
144
}
122
145
@@ -155,4 +178,66 @@ public function setRetry(int $retry): Config
155
178
$ this ->retry = $ retry ;
156
179
return $ this ;
157
180
}
181
+
182
+
183
+ public function getHandler ()
184
+ {
185
+ return $ this ->handler ;
186
+ }
187
+
188
+ /**
189
+ * @param $handler
190
+ * @return Config
191
+ */
192
+ public function setHandler ($ handler ): Config
193
+ {
194
+ $ this ->handler = $ handler ;
195
+ return $ this ;
196
+ }
197
+
198
+ /**
199
+ * @return string
200
+ */
201
+ public function getAppSource (): string
202
+ {
203
+ return $ this ->appSource ;
204
+ }
205
+
206
+ /**
207
+ * @param string $appSource
208
+ * @return Config
209
+ */
210
+ public function setAppSource (string $ appSource ): Config
211
+ {
212
+ $ this ->appSource = $ appSource ;
213
+ return $ this ;
214
+ }
215
+
216
+ /**
217
+ * @return AppConfig[]
218
+ */
219
+ public function getAppKeyArray (): array
220
+ {
221
+ return $ this ->appKeyArray ;
222
+ }
223
+
224
+ /**
225
+ * @param AppConfig[] $appKeyArray
226
+ * @return Config
227
+ */
228
+ public function setAppKeyArray (array $ appKeyArray ): Config
229
+ {
230
+ $ this ->appKeyArray = $ appKeyArray ;
231
+ return $ this ;
232
+ }
233
+
234
+ public function getVersionLen ()
235
+ {
236
+ return strlen ($ this ->version );
237
+ }
238
+
239
+ public function getAppIdLen ()
240
+ {
241
+ return strlen ($ this ->getAppID ());
242
+ }
158
243
}
0 commit comments