|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* CallableObject.php |
|
5
|
|
|
* |
|
6
|
|
|
* Jaxon callable object |
|
7
|
|
|
* |
|
8
|
|
|
* This class stores a reference to an object whose methods can be called from |
|
9
|
|
|
* the client via a Jaxon request |
|
10
|
|
|
* |
|
11
|
|
|
* The Jaxon plugin manager will call <CallableObject->getClientScript> so that |
|
12
|
|
|
* stub functions can be generated and sent to the browser. |
|
13
|
|
|
* |
|
14
|
|
|
* @package jaxon-core |
|
|
|
|
|
|
15
|
|
|
* @author Jared White |
|
|
|
|
|
|
16
|
|
|
* @author J. Max Wilson |
|
|
|
|
|
|
17
|
|
|
* @author Joseph Woolley |
|
|
|
|
|
|
18
|
|
|
* @author Steffen Konerow |
|
|
|
|
|
|
19
|
|
|
* @author Thierry Feuzeu <[email protected]> |
|
20
|
|
|
* @copyright Copyright (c) 2005-2007 by Jared White & J. Max Wilson |
|
|
|
|
|
|
21
|
|
|
* @copyright Copyright (c) 2008-2010 by Joseph Woolley, Steffen Konerow, Jared White & J. Max Wilson |
|
|
|
|
|
|
22
|
|
|
* @copyright 2016 Thierry Feuzeu <[email protected]> |
|
23
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License |
|
24
|
|
|
* @link https://github.com/jaxon-php/jaxon-core |
|
25
|
|
|
*/ |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
namespace Jaxon\Plugin\Request\CallableClass; |
|
28
|
|
|
|
|
29
|
|
|
use Jaxon\App\CallableClass; |
|
30
|
|
|
use Jaxon\Di\Container; |
|
31
|
|
|
use Jaxon\Exception\SetupException; |
|
32
|
|
|
use Jaxon\Request\Target; |
|
33
|
|
|
use Jaxon\Response\ResponseInterface; |
|
34
|
|
|
|
|
35
|
|
|
use ReflectionClass; |
|
36
|
|
|
use ReflectionException; |
|
37
|
|
|
use ReflectionMethod; |
|
38
|
|
|
use ReflectionProperty; |
|
39
|
|
|
|
|
40
|
|
|
use function array_filter; |
|
41
|
|
|
use function array_map; |
|
42
|
|
|
use function array_merge; |
|
43
|
|
|
use function array_unique; |
|
44
|
|
|
use function call_user_func; |
|
45
|
|
|
use function in_array; |
|
46
|
|
|
use function is_array; |
|
47
|
|
|
use function is_string; |
|
48
|
|
|
use function json_encode; |
|
49
|
|
|
use function str_replace; |
|
50
|
|
|
use function substr; |
|
51
|
|
|
|
|
52
|
|
|
class CallableObject |
|
|
|
|
|
|
53
|
|
|
{ |
|
54
|
|
|
/** |
|
55
|
|
|
* The DI container |
|
56
|
|
|
* |
|
57
|
|
|
* @var Container |
|
58
|
|
|
*/ |
|
59
|
|
|
protected $di; |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* The reflection class of the user registered callable object |
|
63
|
|
|
* |
|
64
|
|
|
* @var ReflectionClass |
|
65
|
|
|
*/ |
|
66
|
|
|
private $xReflectionClass; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* A list of methods of the user registered callable object the library must not export to javascript |
|
70
|
|
|
* |
|
71
|
|
|
* @var array |
|
72
|
|
|
*/ |
|
73
|
|
|
private $aProtectedMethods = []; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* A list of methods to call before processing the request |
|
77
|
|
|
* |
|
78
|
|
|
* @var array |
|
79
|
|
|
*/ |
|
80
|
|
|
private $aBeforeMethods = []; |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* A list of methods to call after processing the request |
|
84
|
|
|
* |
|
85
|
|
|
* @var array |
|
86
|
|
|
*/ |
|
87
|
|
|
private $aAfterMethods = []; |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* The callable object options |
|
91
|
|
|
* |
|
92
|
|
|
* @var array |
|
93
|
|
|
*/ |
|
94
|
|
|
private $aOptions = []; |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* The character to use as separator in javascript class names |
|
98
|
|
|
* |
|
99
|
|
|
* @var string |
|
100
|
|
|
*/ |
|
101
|
|
|
private $sSeparator = '.'; |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Check if the js code for this object must be generated |
|
105
|
|
|
* |
|
106
|
|
|
* @var bool |
|
|
|
|
|
|
107
|
|
|
*/ |
|
108
|
|
|
private $bExcluded = false; |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* The user registered callable object |
|
112
|
|
|
* |
|
113
|
|
|
* @var object |
|
114
|
|
|
*/ |
|
115
|
|
|
private $xRegisteredObject = null; |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* The attributes to inject in the user registered callable object |
|
119
|
|
|
* |
|
120
|
|
|
* @var array |
|
121
|
|
|
*/ |
|
122
|
|
|
private $aAttributes = []; |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* The target of the Jaxon call |
|
126
|
|
|
* |
|
127
|
|
|
* @var Target |
|
128
|
|
|
*/ |
|
129
|
|
|
private $xTarget; |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* The class constructor |
|
133
|
|
|
* |
|
134
|
|
|
* @param Container $di |
|
|
|
|
|
|
135
|
|
|
* @param ReflectionClass $xReflectionClass The reflection class |
|
|
|
|
|
|
136
|
|
|
* |
|
137
|
|
|
*/ |
|
138
|
|
|
public function __construct(Container $di, ReflectionClass $xReflectionClass) |
|
|
|
|
|
|
139
|
|
|
{ |
|
140
|
|
|
$this->di = $di; |
|
|
|
|
|
|
141
|
|
|
$this->xReflectionClass = $xReflectionClass; |
|
142
|
|
|
} |
|
|
|
|
|
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Get callable object options |
|
146
|
|
|
* |
|
147
|
|
|
* @return array |
|
148
|
|
|
*/ |
|
149
|
|
|
public function getOptions(): array |
|
150
|
|
|
{ |
|
151
|
|
|
return $this->aOptions; |
|
152
|
|
|
} |
|
|
|
|
|
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* Check if the js code for this object must be generated |
|
156
|
|
|
* |
|
157
|
|
|
* @return bool |
|
158
|
|
|
*/ |
|
159
|
|
|
public function excluded(): bool |
|
160
|
|
|
{ |
|
161
|
|
|
return $this->bExcluded; |
|
162
|
|
|
} |
|
|
|
|
|
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* Set callable object options |
|
166
|
|
|
* |
|
167
|
|
|
* @param array $aOptions |
|
|
|
|
|
|
168
|
|
|
* |
|
169
|
|
|
* @return void |
|
170
|
|
|
*/ |
|
171
|
|
|
public function setOptions(array $aOptions) |
|
172
|
|
|
{ |
|
173
|
|
|
$this->aOptions = $aOptions; |
|
174
|
|
|
} |
|
|
|
|
|
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* Get the name of the corresponding javascript class |
|
178
|
|
|
* |
|
179
|
|
|
* @return string |
|
180
|
|
|
*/ |
|
181
|
|
|
public function getJsName(): string |
|
182
|
|
|
{ |
|
183
|
|
|
return str_replace('\\', $this->sSeparator, $this->xReflectionClass->getName()); |
|
184
|
|
|
} |
|
|
|
|
|
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* Set hook methods |
|
188
|
|
|
* |
|
189
|
|
|
* @param array $aHookMethods The array of hook methods |
|
|
|
|
|
|
190
|
|
|
* @param string|array $xValue The value of the configuration option |
|
|
|
|
|
|
191
|
|
|
* |
|
192
|
|
|
* @return void |
|
193
|
|
|
*/ |
|
194
|
|
|
private function setHookMethods(array &$aHookMethods, $xValue) |
|
195
|
|
|
{ |
|
196
|
|
|
foreach($xValue as $sCalledMethod => $xMethodToCall) |
|
197
|
|
|
{ |
|
198
|
|
|
if(is_array($xMethodToCall)) |
|
199
|
|
|
{ |
|
200
|
|
|
$aHookMethods[$sCalledMethod] = $xMethodToCall; |
|
201
|
|
|
} |
|
202
|
|
|
elseif(is_string($xMethodToCall)) |
|
203
|
|
|
{ |
|
204
|
|
|
$aHookMethods[$sCalledMethod] = [$xMethodToCall]; |
|
205
|
|
|
} |
|
206
|
|
|
} |
|
207
|
|
|
} |
|
|
|
|
|
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* Set configuration options / call options for each method |
|
211
|
|
|
* |
|
212
|
|
|
* @param string $sName The name of the configuration option |
|
|
|
|
|
|
213
|
|
|
* @param string|array $xValue The value of the configuration option |
|
|
|
|
|
|
214
|
|
|
* |
|
215
|
|
|
* @return void |
|
216
|
|
|
*/ |
|
217
|
|
|
public function configure(string $sName, $xValue) |
|
218
|
|
|
{ |
|
219
|
|
|
switch($sName) |
|
220
|
|
|
{ |
|
221
|
|
|
// Set the separator |
|
222
|
|
|
case 'separator': |
|
223
|
|
|
if($xValue === '_' || $xValue === '.') |
|
224
|
|
|
{ |
|
225
|
|
|
$this->sSeparator = $xValue; |
|
226
|
|
|
} |
|
227
|
|
|
break; |
|
228
|
|
|
// Set the protected methods |
|
229
|
|
|
case 'protected': |
|
230
|
|
|
if(is_array($xValue)) |
|
231
|
|
|
{ |
|
232
|
|
|
$this->aProtectedMethods = array_merge($this->aProtectedMethods, $xValue); |
|
233
|
|
|
} |
|
234
|
|
|
break; |
|
235
|
|
|
// Set the methods to call before processing the request |
|
236
|
|
|
case '__before': |
|
237
|
|
|
$this->setHookMethods($this->aBeforeMethods, $xValue); |
|
238
|
|
|
break; |
|
239
|
|
|
// Set the methods to call after processing the request |
|
240
|
|
|
case '__after': |
|
241
|
|
|
$this->setHookMethods($this->aAfterMethods, $xValue); |
|
242
|
|
|
break; |
|
243
|
|
|
// Set the attributes to inject in the callable object |
|
244
|
|
|
case '__di': |
|
245
|
|
|
$this->aAttributes = array_merge($this->aAttributes, $xValue); |
|
|
|
|
|
|
246
|
|
|
break; |
|
247
|
|
|
case 'excluded': |
|
248
|
|
|
$this->bExcluded = (bool)$xValue; |
|
249
|
|
|
break; |
|
250
|
|
|
default: |
|
251
|
|
|
break; |
|
252
|
|
|
} |
|
253
|
|
|
} |
|
|
|
|
|
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* Get the public and protected attributes of the callable object |
|
257
|
|
|
* |
|
258
|
|
|
* @return array |
|
259
|
|
|
*/ |
|
260
|
|
|
public function getProperties(): array |
|
261
|
|
|
{ |
|
262
|
|
|
return array_map(function($xProperty) { |
|
263
|
|
|
return $xProperty->getName(); |
|
264
|
|
|
}, $this->xReflectionClass->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED)); |
|
265
|
|
|
} |
|
|
|
|
|
|
266
|
|
|
|
|
267
|
|
|
/** |
|
268
|
|
|
* Get the public methods of the callable object |
|
269
|
|
|
* |
|
270
|
|
|
* @param array $aProtectedMethods The protected methods |
|
|
|
|
|
|
271
|
|
|
* |
|
272
|
|
|
* @return array |
|
273
|
|
|
*/ |
|
274
|
|
|
public function getPublicMethods(array $aProtectedMethods = []): array |
|
275
|
|
|
{ |
|
276
|
|
|
$aMethods = array_map(function($xMethod) { |
|
277
|
|
|
return $xMethod->getShortName(); |
|
278
|
|
|
}, $this->xReflectionClass->getMethods(ReflectionMethod::IS_PUBLIC)); |
|
279
|
|
|
|
|
280
|
|
|
return array_filter($aMethods, function($sMethodName) use($aProtectedMethods) { |
|
281
|
|
|
// Don't take magic __call, __construct, __destruct methods |
|
282
|
|
|
// Don't take protected methods |
|
283
|
|
|
return substr($sMethodName, 0, 2) !== '__' && |
|
284
|
|
|
!in_array($sMethodName, $aProtectedMethods) && |
|
285
|
|
|
!in_array($sMethodName, $this->aProtectedMethods); |
|
286
|
|
|
}); |
|
287
|
|
|
} |
|
|
|
|
|
|
288
|
|
|
|
|
289
|
|
|
/** |
|
|
|
|
|
|
290
|
|
|
* @param array $aCommonOptions |
|
|
|
|
|
|
291
|
|
|
* @param array $aMethodOptions |
|
|
|
|
|
|
292
|
|
|
* @param string $sMethodName |
|
|
|
|
|
|
293
|
|
|
* |
|
294
|
|
|
* @return mixed |
|
295
|
|
|
*/ |
|
296
|
|
|
private function getOptionValue(array $aCommonOptions, array $aMethodOptions, string $sOptionName) |
|
297
|
|
|
{ |
|
298
|
|
|
if(!isset($aCommonOptions[$sOptionName])) |
|
299
|
|
|
{ |
|
300
|
|
|
return $aMethodOptions[$sOptionName]; |
|
301
|
|
|
} |
|
302
|
|
|
if(!isset($aMethodOptions[$sOptionName])) |
|
303
|
|
|
{ |
|
304
|
|
|
return $aCommonOptions[$sOptionName]; |
|
305
|
|
|
} |
|
306
|
|
|
// If both are not arrays, return the latest. |
|
307
|
|
|
if(!is_array($aCommonOptions[$sOptionName]) && !is_array($aMethodOptions[$sOptionName])) |
|
308
|
|
|
{ |
|
309
|
|
|
return $aMethodOptions[$sOptionName]; |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
// Merge the options. |
|
313
|
|
|
$_aCommonOptions = is_array($aCommonOptions[$sOptionName]) ? |
|
|
|
|
|
|
314
|
|
|
$aCommonOptions[$sOptionName] : [$aCommonOptions[$sOptionName]]; |
|
315
|
|
|
$_aMethodOptions = is_array($aMethodOptions[$sOptionName]) ? |
|
|
|
|
|
|
316
|
|
|
$aMethodOptions[$sOptionName] : [$aMethodOptions[$sOptionName]]; |
|
317
|
|
|
return array_merge($_aCommonOptions, $_aMethodOptions); |
|
318
|
|
|
} |
|
|
|
|
|
|
319
|
|
|
|
|
320
|
|
|
/** |
|
321
|
|
|
* @param string $sMethodName |
|
|
|
|
|
|
322
|
|
|
* |
|
323
|
|
|
* @return array |
|
324
|
|
|
*/ |
|
325
|
|
|
private function getMethodOptions(string $sMethodName): array |
|
326
|
|
|
{ |
|
327
|
|
|
$aCommonOptions = isset($this->aOptions['*']) ? $this->aOptions['*'] : []; |
|
328
|
|
|
$aMethodOptions = isset($this->aOptions[$sMethodName]) ? $this->aOptions[$sMethodName] : []; |
|
329
|
|
|
$aOptionNames = array_unique(array_merge(array_keys($aCommonOptions), array_keys($aMethodOptions))); |
|
|
|
|
|
|
330
|
|
|
$aOptions = []; |
|
|
|
|
|
|
331
|
|
|
foreach($aOptionNames as $sOptionName) |
|
332
|
|
|
{ |
|
333
|
|
|
$aOptions[$sOptionName] = $this->getOptionValue($aCommonOptions, $aMethodOptions, $sOptionName); |
|
334
|
|
|
} |
|
335
|
|
|
return $aOptions; |
|
336
|
|
|
} |
|
|
|
|
|
|
337
|
|
|
|
|
338
|
|
|
/** |
|
339
|
|
|
* Return a list of methods of the callable object to export to javascript |
|
340
|
|
|
* |
|
341
|
|
|
* @param array $aProtectedMethods The protected methods |
|
|
|
|
|
|
342
|
|
|
* |
|
343
|
|
|
* @return array |
|
344
|
|
|
*/ |
|
345
|
|
|
public function getCallableMethods(array $aProtectedMethods): array |
|
346
|
|
|
{ |
|
347
|
|
|
// Convert an option to a string to be displayed in the js script template. |
|
348
|
|
|
$fConvertOption = function($xOption) { |
|
349
|
|
|
return is_array($xOption) ? json_encode($xOption) : $xOption; |
|
350
|
|
|
}; |
|
351
|
|
|
|
|
352
|
|
|
return array_map(function($sMethodName) use($fConvertOption) { |
|
353
|
|
|
return [ |
|
354
|
|
|
'name' => $sMethodName, |
|
355
|
|
|
'config' => array_map($fConvertOption, $this->getMethodOptions($sMethodName)), |
|
356
|
|
|
]; |
|
357
|
|
|
}, $this->getPublicMethods($aProtectedMethods)); |
|
358
|
|
|
} |
|
|
|
|
|
|
359
|
|
|
|
|
360
|
|
|
/** |
|
361
|
|
|
* Get the registered callable object |
|
362
|
|
|
* |
|
363
|
|
|
* @return null|object |
|
364
|
|
|
*/ |
|
365
|
|
|
public function getRegisteredObject() |
|
366
|
|
|
{ |
|
367
|
|
|
return $this->di->g($this->xReflectionClass->getName()); |
|
368
|
|
|
} |
|
|
|
|
|
|
369
|
|
|
|
|
370
|
|
|
/** |
|
371
|
|
|
* Check if the specified method name is one of the methods of the registered callable object |
|
372
|
|
|
* |
|
373
|
|
|
* @param string $sMethod The name of the method to check |
|
|
|
|
|
|
374
|
|
|
* |
|
375
|
|
|
* @return bool |
|
376
|
|
|
*/ |
|
377
|
|
|
public function hasMethod(string $sMethod): bool |
|
378
|
|
|
{ |
|
379
|
|
|
return $this->xReflectionClass->hasMethod($sMethod); |
|
380
|
|
|
} |
|
|
|
|
|
|
381
|
|
|
|
|
382
|
|
|
/** |
|
383
|
|
|
* Call the specified method of the registered callable object using the specified array of arguments |
|
384
|
|
|
* |
|
385
|
|
|
* @param string $sMethod The method name |
|
|
|
|
|
|
386
|
|
|
* @param array $aArgs The method arguments |
|
|
|
|
|
|
387
|
|
|
* @param bool $bAccessible If false, only calls to public method are allowed |
|
|
|
|
|
|
388
|
|
|
* |
|
389
|
|
|
* @return mixed |
|
390
|
|
|
* @throws ReflectionException |
|
391
|
|
|
*/ |
|
392
|
|
|
private function callMethod(string $sMethod, array $aArgs, bool $bAccessible) |
|
393
|
|
|
{ |
|
394
|
|
|
$reflectionMethod = $this->xReflectionClass->getMethod($sMethod); |
|
395
|
|
|
$reflectionMethod->setAccessible($bAccessible); // Make it possible to call protected methods |
|
396
|
|
|
return $reflectionMethod->invokeArgs($this->xRegisteredObject, $aArgs); |
|
397
|
|
|
} |
|
|
|
|
|
|
398
|
|
|
|
|
399
|
|
|
/** |
|
400
|
|
|
* Call the specified method of the registered callable object using the specified array of arguments |
|
401
|
|
|
* |
|
402
|
|
|
* @param array $aHookMethods The method config options |
|
|
|
|
|
|
403
|
|
|
* |
|
404
|
|
|
* @return void |
|
405
|
|
|
* @throws ReflectionException |
|
406
|
|
|
*/ |
|
407
|
|
|
private function callHookMethods(array $aHookMethods) |
|
408
|
|
|
{ |
|
409
|
|
|
$sMethod = $this->xTarget->getMethodName(); |
|
410
|
|
|
$aArgs = $this->xTarget->getMethodArgs(); |
|
|
|
|
|
|
411
|
|
|
// The hooks defined at method level override those defined at class level. |
|
412
|
|
|
// $aMethods = $aHookMethods[$sMethod] ?? $aHookMethods['*'] ?? []; |
|
413
|
|
|
// The hooks defined at method level are merged with those defined at class level. |
|
414
|
|
|
$aMethods = array_merge($aHookMethods['*'] ?? [], $aHookMethods[$sMethod] ?? []); |
|
415
|
|
|
foreach($aMethods as $xKey => $xValue) |
|
416
|
|
|
{ |
|
417
|
|
|
$sHookName = $xValue; |
|
418
|
|
|
$aHookArgs = []; |
|
419
|
|
|
if(is_string($xKey)) |
|
420
|
|
|
{ |
|
421
|
|
|
$sHookName = $xKey; |
|
422
|
|
|
$aHookArgs = is_array($xValue) ? $xValue : [$xValue]; |
|
423
|
|
|
// The name and arguments of the method can be passed to the hooks. |
|
424
|
|
|
/*$aHookArgs = array_map(function($xHookArg) use($sMethod, $aArgs) { |
|
|
|
|
|
|
425
|
|
|
switch($xHookArg) |
|
426
|
|
|
{ |
|
427
|
|
|
case '__method__': |
|
428
|
|
|
return $sMethod; |
|
429
|
|
|
case '__args__': |
|
430
|
|
|
return $aArgs; |
|
431
|
|
|
default: |
|
432
|
|
|
return $xHookArg; |
|
433
|
|
|
} |
|
434
|
|
|
}, $aHookArgs);*/ |
|
435
|
|
|
} |
|
436
|
|
|
$this->callMethod($sHookName, $aHookArgs, true); |
|
437
|
|
|
} |
|
438
|
|
|
} |
|
|
|
|
|
|
439
|
|
|
|
|
440
|
|
|
/** |
|
441
|
|
|
* Call the specified method of the registered callable object using the specified array of arguments |
|
442
|
|
|
* |
|
443
|
|
|
* @param Target $xTarget The target of the Jaxon call |
|
444
|
|
|
* |
|
445
|
|
|
* @return null|ResponseInterface |
|
446
|
|
|
* @throws ReflectionException |
|
447
|
|
|
* @throws SetupException |
|
448
|
|
|
*/ |
|
449
|
|
|
public function call(Target $xTarget): ?ResponseInterface |
|
450
|
|
|
{ |
|
451
|
|
|
$this->xRegisteredObject = $this->getRegisteredObject(); |
|
452
|
|
|
$this->xTarget = $xTarget; |
|
|
|
|
|
|
453
|
|
|
$sMethod = $xTarget->getMethodName(); |
|
|
|
|
|
|
454
|
|
|
|
|
455
|
|
|
// Set attributes from the DI container |
|
456
|
|
|
// The attributes defined at method level override those defined at class level. |
|
457
|
|
|
// $aAttributes = $this->aAttributes[$sMethod] ?? $this->aAttributes['*'] ?? []; |
|
458
|
|
|
// The attributes defined at method level are merged with those defined at class level. |
|
459
|
|
|
$aAttributes = array_merge($this->aAttributes['*'] ?? [], $this->aAttributes[$sMethod] ?? []); |
|
460
|
|
|
foreach($aAttributes as $sName => $sClass) |
|
461
|
|
|
{ |
|
462
|
|
|
// Set the protected attributes of the object |
|
463
|
|
|
$cSetter = function($c) use($sName, $sClass) { |
|
464
|
|
|
// Warning: dynamic properties will be deprecated in PHP8.2. |
|
465
|
|
|
$this->$sName = $c->get($sClass); |
|
466
|
|
|
}; |
|
467
|
|
|
// Can now access protected attributes |
|
468
|
|
|
call_user_func($cSetter->bindTo($this->xRegisteredObject, $this->xRegisteredObject), $this->di); |
|
469
|
|
|
} |
|
470
|
|
|
|
|
471
|
|
|
// Set the Jaxon request target in the helper |
|
472
|
|
|
if($this->xRegisteredObject instanceof CallableClass) |
|
473
|
|
|
{ |
|
474
|
|
|
// Set the protected attributes of the object |
|
475
|
|
|
$cSetter = function() use($xTarget) { |
|
476
|
|
|
$this->xCallableClassHelper->xTarget = $xTarget; |
|
|
|
|
|
|
477
|
|
|
}; |
|
478
|
|
|
// Can now access protected attributes |
|
479
|
|
|
call_user_func($cSetter->bindTo($this->xRegisteredObject, $this->xRegisteredObject)); |
|
480
|
|
|
} |
|
481
|
|
|
|
|
482
|
|
|
// Methods to call before processing the request |
|
483
|
|
|
$this->callHookMethods($this->aBeforeMethods); |
|
484
|
|
|
|
|
485
|
|
|
// Call the request method |
|
486
|
|
|
$xResponse = $this->callMethod($sMethod, $this->xTarget->getMethodArgs(), false); |
|
487
|
|
|
|
|
488
|
|
|
// Methods to call after processing the request |
|
489
|
|
|
$this->callHookMethods($this->aAfterMethods); |
|
490
|
|
|
return $xResponse; |
|
491
|
|
|
} |
|
|
|
|
|
|
492
|
|
|
} |
|
493
|
|
|
|