|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Target.php - Jaxon Request Target |
|
5
|
|
|
* |
|
6
|
|
|
* This class contains the name of the function or class and method targetted by a Jaxon request. |
|
7
|
|
|
* |
|
8
|
|
|
* @package jaxon-core |
|
|
|
|
|
|
9
|
|
|
* @author Thierry Feuzeu <[email protected]> |
|
10
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License |
|
11
|
|
|
* @link https://github.com/jaxon-php/jaxon-core |
|
12
|
|
|
*/ |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
namespace Jaxon\Request; |
|
15
|
|
|
|
|
16
|
|
|
class Target implements TargetInterface |
|
|
|
|
|
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* The target type for function. |
|
20
|
|
|
* |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
const TYPE_FUNCTION = 'TargetFunction'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* The target type for class. |
|
27
|
|
|
* |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
const TYPE_CLASS = 'TargetClass'; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* The target type. |
|
34
|
|
|
* |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
private $sType = ''; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* The target function name. |
|
41
|
|
|
* |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
private $sFunctionName = ''; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* The target class name. |
|
48
|
|
|
* |
|
49
|
|
|
* @var string |
|
50
|
|
|
*/ |
|
51
|
|
|
private $sClassName = ''; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* The target method name. |
|
55
|
|
|
* |
|
56
|
|
|
* @var string |
|
57
|
|
|
*/ |
|
58
|
|
|
private $sMethodName = ''; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* The target method args. |
|
62
|
|
|
* |
|
63
|
|
|
* @var array |
|
64
|
|
|
*/ |
|
65
|
|
|
private $aMethodArgs = []; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* The constructor |
|
69
|
|
|
* |
|
70
|
|
|
* @param string $sType The target type |
|
|
|
|
|
|
71
|
|
|
* @param string $sFunctionName The function name |
|
|
|
|
|
|
72
|
|
|
* @param string $sClassName The class name |
|
73
|
|
|
* @param string $sMethodName The method name |
|
|
|
|
|
|
74
|
|
|
* @param array $aMethodArgs The method args |
|
|
|
|
|
|
75
|
|
|
*/ |
|
76
|
|
|
private function __construct(string $sType, string $sFunctionName, string $sClassName, string $sMethodName, array $aMethodArgs = []) |
|
|
|
|
|
|
77
|
|
|
{ |
|
78
|
|
|
$this->sType = $sType; |
|
|
|
|
|
|
79
|
|
|
$this->sFunctionName = $sFunctionName; |
|
80
|
|
|
$this->sClassName = $sClassName; |
|
|
|
|
|
|
81
|
|
|
$this->sMethodName = $sMethodName; |
|
|
|
|
|
|
82
|
|
|
$this->aMethodArgs = $aMethodArgs; |
|
|
|
|
|
|
83
|
|
|
} |
|
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Create a target of type Function |
|
87
|
|
|
* |
|
88
|
|
|
* @param string $sFunctionName The function name |
|
|
|
|
|
|
89
|
|
|
* |
|
90
|
|
|
* @return Target |
|
91
|
|
|
*/ |
|
92
|
|
|
public static function makeFunction(string $sFunctionName): Target |
|
93
|
|
|
{ |
|
94
|
|
|
return new Target(self::TYPE_FUNCTION, $sFunctionName, '', ''); |
|
95
|
|
|
} |
|
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Create a target of type Class |
|
99
|
|
|
* |
|
100
|
|
|
* @param string $sClassName The class name |
|
|
|
|
|
|
101
|
|
|
* @param string $sMethodName The method name |
|
|
|
|
|
|
102
|
|
|
* |
|
103
|
|
|
* @return Target |
|
104
|
|
|
*/ |
|
105
|
|
|
public static function makeClass(string $sClassName, string $sMethodName): Target |
|
106
|
|
|
{ |
|
107
|
|
|
return new Target(self::TYPE_CLASS, '', $sClassName, $sMethodName); |
|
108
|
|
|
} |
|
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Check if the target type is Function. |
|
112
|
|
|
* |
|
113
|
|
|
* @return bool |
|
114
|
|
|
*/ |
|
115
|
|
|
public function isFunction(): bool |
|
116
|
|
|
{ |
|
117
|
|
|
return $this->sType === self::TYPE_FUNCTION; |
|
118
|
|
|
} |
|
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Check if the target type is Class. |
|
122
|
|
|
* |
|
123
|
|
|
* @return bool |
|
124
|
|
|
*/ |
|
125
|
|
|
public function isClass(): bool |
|
126
|
|
|
{ |
|
127
|
|
|
return $this->sType === self::TYPE_CLASS; |
|
128
|
|
|
} |
|
|
|
|
|
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* The target function name. |
|
132
|
|
|
* |
|
133
|
|
|
* @return string |
|
134
|
|
|
*/ |
|
135
|
|
|
public function getFunctionName(): string |
|
136
|
|
|
{ |
|
137
|
|
|
return $this->sFunctionName; |
|
138
|
|
|
} |
|
|
|
|
|
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* The target class name. |
|
142
|
|
|
* |
|
143
|
|
|
* @return string |
|
144
|
|
|
*/ |
|
145
|
|
|
public function getClassName(): string |
|
146
|
|
|
{ |
|
147
|
|
|
return $this->sClassName; |
|
148
|
|
|
} |
|
|
|
|
|
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* The target method name. |
|
152
|
|
|
* |
|
153
|
|
|
* @return string |
|
154
|
|
|
*/ |
|
155
|
|
|
public function getMethodName(): string |
|
156
|
|
|
{ |
|
157
|
|
|
return $this->sMethodName; |
|
158
|
|
|
} |
|
|
|
|
|
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* Set the target method name. |
|
162
|
|
|
* |
|
163
|
|
|
* @param array $aMethodArgs |
|
|
|
|
|
|
164
|
|
|
*/ |
|
|
|
|
|
|
165
|
|
|
public function setMethodArgs(array $aMethodArgs): void |
|
166
|
|
|
{ |
|
167
|
|
|
$this->aMethodArgs = $aMethodArgs; |
|
168
|
|
|
} |
|
|
|
|
|
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* The target method args. |
|
172
|
|
|
* |
|
173
|
|
|
* @return array |
|
174
|
|
|
*/ |
|
175
|
|
|
public function getMethodArgs(): array |
|
176
|
|
|
{ |
|
177
|
|
|
return $this->aMethodArgs; |
|
178
|
|
|
} |
|
|
|
|
|
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* The target method name. |
|
182
|
|
|
* |
|
183
|
|
|
* @return string |
|
184
|
|
|
*/ |
|
185
|
|
|
public function method(): string |
|
186
|
|
|
{ |
|
187
|
|
|
return $this->sMethodName; |
|
188
|
|
|
} |
|
|
|
|
|
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* The target method args. |
|
192
|
|
|
* |
|
193
|
|
|
* @return array |
|
194
|
|
|
*/ |
|
195
|
|
|
public function args(): array |
|
196
|
|
|
{ |
|
197
|
|
|
return $this->aMethodArgs; |
|
198
|
|
|
} |
|
|
|
|
|
|
199
|
|
|
} |
|
200
|
|
|
|