1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
+------------------------------------------------------------------------+ |
4
|
|
|
| Plinker-RPC PHP | |
5
|
|
|
+------------------------------------------------------------------------+ |
6
|
|
|
| Copyright (c)2017-2018 (https://github.com/plinker-rpc/core) | |
7
|
|
|
+------------------------------------------------------------------------+ |
8
|
|
|
| This source file is subject to MIT License | |
9
|
|
|
| that is bundled with this package in the file LICENSE. | |
10
|
|
|
| | |
11
|
|
|
| If you did not receive a copy of the license and are unable to | |
12
|
|
|
| obtain it through the world-wide-web, please send an email | |
13
|
|
|
| to [email protected] so we can send you a copy immediately. | |
14
|
|
|
+------------------------------------------------------------------------+ |
15
|
|
|
| Authors: Lawrence Cherone <[email protected]> | |
16
|
|
|
+------------------------------------------------------------------------+ |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Plinker\Core; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Plinker\Core\Client |
23
|
|
|
*/ |
24
|
|
|
final class Client |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var |
28
|
|
|
*/ |
29
|
|
|
private $component; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var |
33
|
|
|
*/ |
34
|
|
|
private $response; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var |
38
|
|
|
*/ |
39
|
|
|
private $config; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var |
43
|
|
|
*/ |
44
|
|
|
private $curl; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var |
48
|
|
|
*/ |
49
|
|
|
private $signer; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Class construct |
53
|
|
|
* |
54
|
|
|
* @param string $server - server enpoint url |
55
|
|
|
* @param array $config - config array which holds object configuration |
56
|
|
|
* @return void |
57
|
|
|
*/ |
58
|
|
|
public function __construct($server, array $config = []) |
59
|
|
|
{ |
60
|
|
|
$this->config = array_merge([ |
61
|
|
|
"server" => $server, |
62
|
|
|
"secret" => null |
63
|
|
|
], $config); |
64
|
|
|
|
65
|
|
|
// check and set client timeout |
66
|
|
|
if (!isset($this->config["timeout"]) || !is_numeric($this->config["timeout"])) { |
67
|
|
|
$this->config["timeout"] = 10; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Magic getter method, which sets component |
|
|
|
|
73
|
|
|
* |
74
|
|
|
* @param string method - component name |
75
|
|
|
* @return <Plinker\Client> |
76
|
|
|
*/ |
|
|
|
|
77
|
|
|
public function __get($method) |
78
|
|
|
{ |
79
|
|
|
$this->component = $method; |
80
|
|
|
|
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Magic caller method, which calls component |
86
|
|
|
* |
87
|
|
|
* @param string action |
|
|
|
|
88
|
|
|
* @param array params |
|
|
|
|
89
|
|
|
*/ |
90
|
|
|
public function __call($action, array $params) |
91
|
|
|
{ |
92
|
|
|
if (!is_scalar($action)) { |
93
|
|
|
throw new \Exception("Method name has no scalar value"); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
if (!is_array($params)) { |
|
|
|
|
97
|
|
|
throw new \Exception("Params must be given as array"); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
// load curl |
101
|
|
|
if (!$this->curl) { |
102
|
|
|
$this->curl = new Lib\Curl($this->config); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
// load signer |
106
|
|
|
if (!$this->signer) { |
107
|
|
|
$this->signer = new Lib\Signer($this->config); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
// change params array into numeric |
111
|
|
|
$params = array_values($params); |
112
|
|
|
|
113
|
|
|
// unset local private key |
114
|
|
|
unset($this->config["plinker"]["private_key"]); |
115
|
|
|
|
116
|
|
|
$payload = $this->signer->encode([ |
117
|
|
|
"component" => $this->component, |
118
|
|
|
"config" => $this->config, |
119
|
|
|
"action" => $action, |
120
|
|
|
"params" => $params |
121
|
|
|
]); |
122
|
|
|
|
123
|
|
|
$this->response = $this->curl->post($this->config["server"], $payload, [ |
124
|
|
|
"PLINKER: ".$payload["token"] |
125
|
|
|
]); |
126
|
|
|
|
127
|
|
|
// unserialize data |
128
|
|
|
return unserialize($this->response); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths