1 | <?php |
||
16 | class ThreemaGateway_Handler_PhpSdk |
||
17 | { |
||
18 | /** |
||
19 | * @var Singleton |
||
20 | */ |
||
21 | protected static $instance = null; |
||
22 | |||
23 | /** |
||
24 | * @var string Path to Threema Gateway PHP SDK |
||
25 | */ |
||
26 | protected $sdkDir = __DIR__ . '/../threema-msgapi-sdk-php'; |
||
27 | |||
28 | /** |
||
29 | * @var ThreemaGateway_Handler_Settings |
||
30 | */ |
||
31 | protected $settings; |
||
32 | |||
33 | /** |
||
34 | * @var string Version of Threema Gateway PHP SDK |
||
35 | */ |
||
36 | protected $sdkVersion; |
||
37 | |||
38 | /** |
||
39 | * @var int Feature level of PHP SDK |
||
40 | */ |
||
41 | protected $sdkFeatureLevel; |
||
42 | |||
43 | /** |
||
44 | * @var Threema\MsgApi\Tools\CryptTool |
||
45 | */ |
||
46 | protected $cryptTool; |
||
47 | |||
48 | /** |
||
49 | * @var Threema\MsgApi\PublicKeyStore |
||
50 | */ |
||
51 | protected $keystore; |
||
52 | |||
53 | /** |
||
54 | * @var Threema\MsgApi\Connection The connector to the PHP-SDK |
||
55 | */ |
||
56 | protected $connector; |
||
57 | |||
58 | /** |
||
59 | * @var E2EHelper The Threema E2E helper, which is necessary when dealing |
||
60 | * with end-to-end-encrypted messages. |
||
61 | */ |
||
62 | protected $e2eHelper; |
||
63 | |||
64 | /** |
||
65 | * Initiate PHP-SDK. |
||
66 | * |
||
67 | * @param ThreemaGateway_Handler_Settings|null $settings |
||
68 | * @throws XenForo_Exception |
||
69 | */ |
||
70 | protected function __construct($settings = null) |
||
71 | { |
||
72 | // get options |
||
73 | if ($settings !== null) { |
||
74 | $this->settings = $settings; |
||
75 | } else { |
||
76 | $this->settings = new ThreemaGateway_Handler_Settings; |
||
77 | } |
||
78 | |||
79 | // load libraries |
||
80 | $this->loadLib(); |
||
81 | |||
82 | //create keystore |
||
83 | $this->createKeystore(); |
||
84 | |||
85 | //create connection |
||
86 | $this->createConnection(); |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * Prevent cloning for Singleton. |
||
91 | */ |
||
92 | protected function __clone() |
||
93 | { |
||
94 | // I smash clones! |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * SDK startup as a Singleton. |
||
99 | * |
||
100 | * @param ThreemaGateway_Handler_Settings If you already used the settings |
||
101 | * you can pass them here, so the |
||
102 | * class can reuse them. |
||
103 | * @param ThreemaGateway_Handler_Settings $settings |
||
104 | * @throws XenForo_Exception |
||
105 | * @return void |
||
|
|||
106 | */ |
||
107 | public static function getInstance($settings = null) |
||
115 | |||
116 | /** |
||
117 | * Returns the version of the PDP SDK. |
||
118 | * |
||
119 | * @return string |
||
120 | */ |
||
121 | public function getVersion() |
||
125 | |||
126 | /** |
||
127 | * Returns the feature level of the SDK. |
||
128 | * |
||
129 | * @return int |
||
130 | */ |
||
131 | public function getFeatureLevel() |
||
135 | |||
136 | /** |
||
137 | * Returns the connector to the Threema Gateway. |
||
138 | * |
||
139 | * @return Threema\MsgApi\Connection |
||
140 | */ |
||
141 | public function getConnector() |
||
145 | |||
146 | /** |
||
147 | * Returns the E2EHelper to the Threema Gateway. |
||
148 | * |
||
149 | * @throws XenForo_Exception |
||
150 | * @return E2EHelper The connector to the PHP-SDK |
||
151 | */ |
||
152 | public function getE2EHelper() |
||
159 | |||
160 | /** |
||
161 | * Returns a Receiver for a Threema ID. |
||
162 | * |
||
163 | * @param string $threemaId |
||
164 | * |
||
165 | * @return Receiver |
||
166 | */ |
||
167 | public function getReceiver($threemaId) |
||
171 | |||
172 | /** |
||
173 | * Returns the crypt tool. |
||
174 | * |
||
175 | * @return Threema\MsgApi\Tools\CryptTool |
||
176 | */ |
||
177 | public function getCryptTool() |
||
181 | |||
182 | /** |
||
183 | * Returns the settings used for the PHP SDK. |
||
184 | * |
||
185 | * @return ThreemaGateway_Handler_Settings |
||
186 | */ |
||
187 | public function getSettings() |
||
191 | |||
192 | /** |
||
193 | * Loads the PHP-SDK. |
||
194 | * |
||
195 | * @throws XenForo_Exception |
||
196 | */ |
||
197 | protected function loadLib() |
||
221 | |||
222 | /** |
||
223 | * Creates a keystore. |
||
224 | * |
||
225 | * @param |
||
226 | */ |
||
227 | protected function createKeystore() |
||
239 | |||
240 | /** |
||
241 | * Creates a keystore. |
||
242 | */ |
||
243 | protected function createConnection() |
||
259 | |||
260 | /** |
||
261 | * Creates connection settings. |
||
262 | * |
||
263 | * @param string $gatewayId Your own gateway ID |
||
264 | * @param string $gatewaySecret Your own gateway secret |
||
265 | * |
||
266 | * @throws XenForoException |
||
267 | * @return ConnectionSettings |
||
268 | */ |
||
269 | protected function createConnectionSettings($gatewayId, $gatewaySecret) |
||
313 | } |
||
314 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.