|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* General purpose action handler. |
|
4
|
|
|
* |
|
5
|
|
|
* @package ThreemaGateway |
|
6
|
|
|
* @author rugk |
|
7
|
|
|
* @copyright Copyright (c) 2015-2016 rugk |
|
8
|
|
|
* @license MIT |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
abstract class ThreemaGateway_Handler_Action_Abstract |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Gateway PHP SDK store. |
|
15
|
|
|
* |
|
16
|
|
|
* This variable is private as {@link getSdk()} should be used. This makes |
|
17
|
|
|
* sure the SDK is only initialized when it is really needed. |
|
18
|
|
|
* |
|
19
|
|
|
* @var ThreemaGateway_Handler_PhpSdk |
|
20
|
|
|
*/ |
|
21
|
|
|
private $sdk = null; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var ThreemaGateway_Handler_Settings |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $settings; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var ThreemaGateway_Handler_Permissions |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $permissions; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Startup. |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->settings = new ThreemaGateway_Handler_Settings; |
|
39
|
|
|
$this->permissions = ThreemaGateway_Handler_Permissions::getInstance(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Returns the PHP SDK object. |
|
44
|
|
|
* |
|
45
|
|
|
* This is meant for lazy loading the SDK, so it is only loaded when it is |
|
46
|
|
|
* actually accessed. |
|
47
|
|
|
* |
|
48
|
|
|
* @return ThreemaGateway_Handler_PhpSdk |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function getSdk() |
|
51
|
|
|
{ |
|
52
|
|
|
if ($this->sdk === null) { |
|
53
|
|
|
$this->sdk = ThreemaGateway_Handler_PhpSdk::getInstance($this->settings); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return $this->sdk; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Returns the PHP SDK E2EHelper. |
|
61
|
|
|
* |
|
62
|
|
|
* @return Threema\MsgApi\Helpers\E2EHelper |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function getE2EHelper() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->getSdk()->getE2EHelper(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Returns the Threema Receiver. |
|
71
|
|
|
* |
|
72
|
|
|
* Note that you may need to call $this->getSdk(); manually if you want to |
|
73
|
|
|
* pass a specific type via the $type param. |
|
74
|
|
|
* |
|
75
|
|
|
* @param string $value the query value (Threema ID, phone number, …) |
|
76
|
|
|
* @param string $type the type of the queried data (use constzants of Threema\MsgApi\Receiver) |
|
77
|
|
|
* |
|
78
|
|
|
* @return Threema\MsgApi\Receiver |
|
79
|
|
|
*/ |
|
80
|
|
|
protected function getThreemaReceiver($value, $type = null) |
|
81
|
|
|
{ |
|
82
|
|
|
// make sure the SDK is loaded |
|
83
|
|
|
$this->getSdk(); |
|
84
|
|
|
|
|
85
|
|
|
if ($type === null) { |
|
86
|
|
|
$type = Threema\MsgApi\Receiver::TYPE_ID; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
return new Threema\MsgApi\Receiver($value, $type); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Returns the PHP SDK crypt tool. |
|
94
|
|
|
* |
|
95
|
|
|
* @return Threema\MsgApi\Tools\CryptTool |
|
96
|
|
|
*/ |
|
97
|
|
|
protected function getCryptTool() |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->getSdk()->getCryptTool(); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Returns the PHP SDK connector. |
|
104
|
|
|
* |
|
105
|
|
|
* @return Threema\MsgApi\Connection |
|
106
|
|
|
*/ |
|
107
|
|
|
protected function getConnector() |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->getSdk()->getConnector(); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.