1
|
|
|
<?php namespace Comodojo\RpcClient\Processor; |
2
|
|
|
|
3
|
|
|
use \Psr\Log\LoggerInterface; |
4
|
|
|
use \Comodojo\Exception\RpcException; |
5
|
|
|
use \Comodojo\RpcClient\RpcRequest; |
6
|
|
|
use \Comodojo\Xmlrpc\XmlrpcEncoder; |
7
|
|
|
use \Comodojo\Xmlrpc\XmlrpcDecoder; |
8
|
|
|
use \Exception; |
9
|
|
|
|
10
|
|
|
class XmlProcessor implements ProcessorInterface { |
11
|
|
|
|
12
|
|
|
private $encoding; |
13
|
|
|
|
14
|
|
|
private $logger; |
15
|
|
|
|
16
|
|
|
private $encoder; |
17
|
|
|
|
18
|
|
|
private $decoder; |
19
|
|
|
|
20
|
|
|
private $requests; |
21
|
|
|
|
22
|
|
|
public function __construct($encoding, LoggerInterface $logger) { |
23
|
|
|
|
24
|
|
|
$this->encoding = $encoding; |
25
|
|
|
|
26
|
|
|
$this->logger = $logger; |
27
|
|
|
|
28
|
|
|
$this->encoder = new XmlrpcEncoder(); |
29
|
|
|
|
30
|
|
|
$this->decoder = new XmlrpcDecoder(); |
31
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function encode($requests) { |
35
|
|
|
|
36
|
|
|
$this->requests = $requests; |
37
|
|
|
|
38
|
|
|
try { |
39
|
|
|
|
40
|
|
|
$payload = ( sizeof($requests) > 1 ) ? $this->encodeMulticall($requests) : $this->encodeSingleCall($requests[0]); |
41
|
|
|
|
42
|
|
|
} catch (XmlrpcException $xe) { |
|
|
|
|
43
|
|
|
|
44
|
|
|
throw $xe; |
45
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return $payload; |
49
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function decode($response) { |
53
|
|
|
|
54
|
|
|
try { |
55
|
|
|
|
56
|
|
|
$content = $this->decoder->decodeResponse($response); |
57
|
|
|
|
58
|
|
|
if ( $this->decoder->isFault() ) throw new RpcException($content['faultString'], $content['faultCode']); |
59
|
|
|
|
60
|
|
|
} catch (XmlrpcException $xe) { |
|
|
|
|
61
|
|
|
|
62
|
|
|
throw $xe; |
63
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $content; |
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
private function encodeSingleCall(RpcRequest $request) { |
71
|
|
|
|
72
|
|
|
$this->requests = $request; |
73
|
|
|
|
74
|
|
|
$this->logger->notice("Performing a single XML call"); |
75
|
|
|
|
76
|
|
|
$this->logger->debug("Data dump before encoding", $request); |
|
|
|
|
77
|
|
|
|
78
|
|
|
try { |
79
|
|
|
|
80
|
|
|
// encoding |
81
|
|
|
|
82
|
|
|
foreach ( $request->getSpecialTypes() as $key => $value ) { |
83
|
|
|
|
84
|
|
|
$this->encoder->setValueType($key, $value); |
85
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$encoded_request = $this->encoder->encodeCall($request->getMethod(), $request->getParameters()); |
89
|
|
|
|
90
|
|
|
} catch (XmlrpcException $xe) { |
|
|
|
|
91
|
|
|
|
92
|
|
|
throw $xe; |
93
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$this->logger->debug("Data dump after encoding", $encoded_request); |
|
|
|
|
97
|
|
|
|
98
|
|
|
return $encoded_request; |
99
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Perform an xml multicall |
104
|
|
|
* |
105
|
|
|
* @param array $requests |
106
|
|
|
* |
107
|
|
|
* @return array |
108
|
|
|
* |
109
|
|
|
* @throws \Comodojo\Exception\RpcException |
110
|
|
|
* @throws \Comodojo\Exception\HttpException |
111
|
|
|
* @throws \Comodojo\Exception\XmlrpcException |
112
|
|
|
* @throws \Exception |
113
|
|
|
*/ |
114
|
|
|
private function encodeMulticall($requests) { |
115
|
|
|
|
116
|
|
|
$this->requests = $requests; |
117
|
|
|
|
118
|
|
|
$composed_requests = array(); |
119
|
|
|
|
120
|
|
|
$this->logger->notice("Performing an XML multicall"); |
121
|
|
|
|
122
|
|
|
$this->logger->debug("Data dump before encoding", $requests); |
123
|
|
|
|
124
|
|
|
foreach ($requests as $request) { |
125
|
|
|
|
126
|
|
|
$composed_requests[] = array($request->getMethod(), $request->getParameters()); |
127
|
|
|
|
128
|
|
|
foreach ( $request->getSpecialTypes() as $key => $value ) { |
129
|
|
|
|
130
|
|
|
$this->encoder->setValueType($key, $value); |
131
|
|
|
|
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
try { |
137
|
|
|
|
138
|
|
|
$encoded_requests = $this->encoder->setEncoding($this->encoding)->encodeMulticall($composed_requests); |
|
|
|
|
139
|
|
|
|
140
|
|
|
} catch (XmlrpcException $xe) { |
|
|
|
|
141
|
|
|
|
142
|
|
|
throw $xe; |
143
|
|
|
|
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
return $encoded_request; |
|
|
|
|
147
|
|
|
|
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
} |
151
|
|
|
|
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.