|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the overtrue/wechat. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) overtrue <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* MiniProgram.php. |
|
14
|
|
|
* |
|
15
|
|
|
* Part of Overtrue\WeChat. |
|
16
|
|
|
* |
|
17
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
18
|
|
|
* file that was distributed with this source code. |
|
19
|
|
|
* |
|
20
|
|
|
* @author mingyoung <[email protected]> |
|
21
|
|
|
* @copyright 2016 |
|
22
|
|
|
* |
|
23
|
|
|
* @see https://github.com/overtrue |
|
24
|
|
|
* @see http://overtrue.me |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace EasyWeChat\MiniProgram; |
|
28
|
|
|
|
|
29
|
|
|
use EasyWeChat\Core\Exceptions\InvalidArgumentException; |
|
30
|
|
|
use EasyWeChat\MiniProgram\Material\Temporary; |
|
31
|
|
|
use EasyWeChat\MiniProgram\Notice\Notice; |
|
32
|
|
|
use EasyWeChat\MiniProgram\QRCode\QRCode; |
|
33
|
|
|
use EasyWeChat\MiniProgram\Staff\Staff; |
|
34
|
|
|
use EasyWeChat\MiniProgram\User\User; |
|
35
|
|
|
use EasyWeChat\Support\Arr; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Class MiniProgram. |
|
39
|
|
|
* |
|
40
|
|
|
* @property \EasyWeChat\MiniProgram\Server\Guard $server |
|
41
|
|
|
* @property \EasyWeChat\MiniProgram\User\User $user |
|
42
|
|
|
* @property \EasyWeChat\MiniProgram\Notice\Notice $notice |
|
43
|
|
|
* @property \EasyWeChat\MiniProgram\Staff\Staff $staff |
|
44
|
|
|
* @property \EasyWeChat\MiniProgram\QRCode\QRCode $qrcode |
|
45
|
|
|
* @property \EasyWeChat\MiniProgram\Material\Temporary $material_temporary |
|
46
|
|
|
*/ |
|
47
|
|
|
class MiniProgram |
|
48
|
|
|
{ |
|
49
|
|
|
/** |
|
50
|
|
|
* Access Token. |
|
51
|
|
|
* |
|
52
|
|
|
* @var \EasyWeChat\MiniProgram\AccessToken |
|
53
|
|
|
*/ |
|
54
|
|
|
protected $accessToken; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Mini program config. |
|
58
|
|
|
* |
|
59
|
|
|
* @var array |
|
60
|
|
|
*/ |
|
61
|
|
|
protected $config; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Guard. |
|
65
|
|
|
* |
|
66
|
|
|
* @var \EasyWeChat\MiniProgram\Server\Guard |
|
67
|
|
|
*/ |
|
68
|
|
|
protected $server; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Components. |
|
72
|
|
|
* |
|
73
|
|
|
* @var array |
|
74
|
|
|
*/ |
|
75
|
|
|
protected $components = [ |
|
76
|
|
|
'user' => User::class, |
|
77
|
|
|
'notice' => Notice::class, |
|
78
|
|
|
'staff' => Staff::class, |
|
79
|
|
|
'qrcode' => QRCode::class, |
|
80
|
|
|
'material_temporary' => Temporary::class, |
|
81
|
|
|
]; |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* MiniProgram constructor. |
|
85
|
|
|
* |
|
86
|
|
|
* @param \EasyWeChat\MiniProgram\Server\Guard $server |
|
87
|
|
|
* @param \EasyWeChat\MiniProgram\AccessToken $accessToken |
|
88
|
|
|
* @param array $config |
|
89
|
|
|
*/ |
|
90
|
|
|
public function __construct($server, $accessToken, $config) |
|
91
|
|
|
{ |
|
92
|
|
|
$this->server = $server; |
|
93
|
|
|
|
|
94
|
|
|
$this->accessToken = $accessToken; |
|
95
|
|
|
|
|
96
|
|
|
$this->config = $config; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Magic get access. |
|
101
|
|
|
* |
|
102
|
|
|
* @param $name |
|
103
|
|
|
* |
|
104
|
|
|
* @return mixed |
|
105
|
|
|
* |
|
106
|
|
|
* @throws InvalidArgumentException |
|
107
|
|
|
*/ |
|
108
|
|
View Code Duplication |
public function __get($name) |
|
109
|
|
|
{ |
|
110
|
|
|
if (property_exists($this, $name)) { |
|
111
|
|
|
return $this->$name; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
if ($class = Arr::get($this->components, $name)) { |
|
115
|
|
|
return new $class($this->accessToken, $this->config); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
throw new InvalidArgumentException("Property or component \"$name\" does not exists."); |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|