|
1
|
|
|
<?php |
|
2
|
|
|
|
|
|
|
|
|
|
3
|
|
|
namespace Jaxon\Request\Factory; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
|
|
|
|
|
6
|
|
|
* JsCallFactory.php |
|
7
|
|
|
* |
|
8
|
|
|
* Create Jaxon client side requests, which will generate the client script necessary |
|
9
|
|
|
* to invoke a jaxon request from the browser to registered objects. |
|
10
|
|
|
* |
|
11
|
|
|
* @package jaxon-core |
|
12
|
|
|
* @author Thierry Feuzeu |
|
13
|
|
|
* @copyright 2022 Thierry Feuzeu <[email protected]> |
|
14
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License |
|
15
|
|
|
* @link https://github.com/jaxon-php/jaxon-core |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
use Jaxon\App\Dialog\DialogManager; |
|
19
|
|
|
use Jaxon\Request\Js\Call; |
|
20
|
|
|
|
|
21
|
|
|
use function array_shift; |
|
22
|
|
|
use function func_get_args; |
|
23
|
|
|
|
|
24
|
|
|
class JsCallFactory |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $sPrefix; |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var DialogManager |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $xDialogManager; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* The class constructor |
|
38
|
|
|
* |
|
39
|
|
|
* @param string $sPrefix |
|
|
|
|
|
|
40
|
|
|
* @param DialogManager $xDialogManager |
|
|
|
|
|
|
41
|
|
|
*/ |
|
42
|
|
|
public function __construct(string $sPrefix, DialogManager $xDialogManager) |
|
|
|
|
|
|
43
|
|
|
{ |
|
44
|
|
|
$this->sPrefix = $sPrefix; |
|
|
|
|
|
|
45
|
|
|
$this->xDialogManager = $xDialogManager; |
|
46
|
|
|
} |
|
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Generate the javascript code for a call to a given method or function |
|
50
|
|
|
* |
|
51
|
|
|
* @param string $sFunction |
|
|
|
|
|
|
52
|
|
|
* @param array $aArguments |
|
|
|
|
|
|
53
|
|
|
* |
|
54
|
|
|
* @return Call |
|
55
|
|
|
*/ |
|
56
|
|
|
public function __call(string $sFunction, array $aArguments): Call |
|
57
|
|
|
{ |
|
58
|
|
|
$xCall = new Call($this->sPrefix . $sFunction); |
|
59
|
|
|
$xCall->setDialogManager($this->xDialogManager); |
|
60
|
|
|
$xCall->addParameters($aArguments); |
|
61
|
|
|
return $xCall; |
|
62
|
|
|
} |
|
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Return the javascript call to a Jaxon function or object method |
|
66
|
|
|
* |
|
67
|
|
|
* @param string $sFunction The function or method (without class) name |
|
|
|
|
|
|
68
|
|
|
* |
|
69
|
|
|
* @return Call |
|
70
|
|
|
* @deprecated |
|
71
|
|
|
*/ |
|
72
|
|
|
public function call(string $sFunction): Call |
|
73
|
|
|
{ |
|
74
|
|
|
$aArguments = func_get_args(); |
|
75
|
|
|
// Remove the function name from the arguments array. |
|
76
|
|
|
array_shift($aArguments); |
|
77
|
|
|
return $this->__call($sFunction, $aArguments); |
|
78
|
|
|
} |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|