1 | <?php |
||
18 | class Requestor |
||
19 | { |
||
20 | /** |
||
21 | * @var ApiContext |
||
22 | */ |
||
23 | protected static $apiContext; |
||
24 | |||
25 | /** |
||
26 | * @var Client |
||
27 | */ |
||
28 | protected static $httpClient; |
||
29 | |||
30 | /** |
||
31 | * @var Token |
||
32 | */ |
||
33 | protected static $token; |
||
34 | |||
35 | /** |
||
36 | * 获取 access token. |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | const GET_TOKEN_ENDPOINT = 'https://open.youzan.com/oauth/token'; |
||
41 | |||
42 | /** |
||
43 | * 创建支付二维码 |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | const CREATE_QR_ENDPOINT = 'https://open.youzan.com/api/oauthentry/youzan.pay.qrcode/3.0.0/create'; |
||
48 | |||
49 | /** |
||
50 | * 获取支付二维码 |
||
51 | * |
||
52 | * @var string |
||
53 | */ |
||
54 | const GET_QR_ENDPOINT = 'https://open.youzan.com/api/oauthentry/youzan.pay.qrcode/3.0.0/get'; |
||
55 | |||
56 | /** |
||
57 | * 获取qr对应的交易. |
||
58 | * |
||
59 | * @var string |
||
60 | */ |
||
61 | const GET_TRADES_ENDPOINT = 'https://open.youzan.com/api/oauthentry/youzan.trades.qr/3.0.0/get'; |
||
62 | |||
63 | /** |
||
64 | * 获取交易. |
||
65 | * |
||
66 | * @var string |
||
67 | */ |
||
68 | const GET_TRADE_ENDPOINT = 'https://open.youzan.com/api/oauthentry/youzan.trade/3.0.0/get'; |
||
69 | |||
70 | /** |
||
71 | * 获取access token. |
||
72 | * |
||
73 | * @return Token |
||
74 | */ |
||
75 | public static function getAccessToken() |
||
93 | |||
94 | /** |
||
95 | * 持久化qrcode. |
||
96 | * |
||
97 | * @param QRCode $qrCode |
||
98 | */ |
||
99 | public static function persistQrCode(QRCode $qrCode) |
||
111 | |||
112 | /** |
||
113 | * 检查QRCode支付结果. |
||
114 | * |
||
115 | * @param int|QRCode $qrCode |
||
116 | * |
||
117 | * @return bool |
||
118 | */ |
||
119 | public static function checkQRCodePayResult($qrCode) |
||
133 | |||
134 | /** |
||
135 | * 获取交易. |
||
136 | * |
||
137 | * @param int $id |
||
138 | * |
||
139 | * @return Trade |
||
140 | */ |
||
141 | public static function getTrade($id) |
||
154 | |||
155 | protected static function setRequest($method, $uri, $parameters) |
||
182 | |||
183 | /** |
||
184 | * @param ApiContext $apiContext |
||
185 | */ |
||
186 | public static function setApiContext($apiContext) |
||
190 | |||
191 | /** |
||
192 | * @param Client $httpClient |
||
193 | */ |
||
194 | public static function setHttpClient($httpClient) |
||
198 | |||
199 | /** |
||
200 | * @param Token $token |
||
201 | */ |
||
202 | public static function setToken($token) |
||
206 | } |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.