Completed
Push — master ( ca35a2...89bb00 )
by Jesus
02:05
created

BigBlueButton::getUpdateRecordingsUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
4
 *
5
 * Copyright (c) 2016 BigBlueButton Inc. and by respective authors (see below).
6
 *
7
 * This program is free software; you can redistribute it and/or modify it under the
8
 * terms of the GNU Lesser General Public License as published by the Free Software
9
 * Foundation; either version 3.0 of the License, or (at your option) any later
10
 * version.
11
 *
12
 * BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
13
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
14
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License along
17
 * with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
18
 */
19
namespace BigBlueButton;
20
21
use BigBlueButton\Core\ApiMethod;
22
use BigBlueButton\Parameters\CreateMeetingParameters;
23
use BigBlueButton\Parameters\DeleteRecordingsParameters;
24
use BigBlueButton\Parameters\EndMeetingParameters;
25
use BigBlueButton\Parameters\GetMeetingInfoParameters;
26
use BigBlueButton\Parameters\GetRecordingsParameters;
27
use BigBlueButton\Parameters\IsMeetingRunningParameters;
28
use BigBlueButton\Parameters\JoinMeetingParameters;
29
use BigBlueButton\Parameters\PublishRecordingsParameters;
30
use BigBlueButton\Parameters\UpdateRecordingsParameters;
31
use BigBlueButton\Responses\ApiVersionResponse;
32
use BigBlueButton\Responses\CreateMeetingResponse;
33
use BigBlueButton\Responses\DeleteRecordingsResponse;
34
use BigBlueButton\Responses\EndMeetingResponse;
35
use BigBlueButton\Responses\GetDefaultConfigXMLResponse;
36
use BigBlueButton\Responses\GetMeetingInfoResponse;
37
use BigBlueButton\Responses\GetMeetingsResponse;
38
use BigBlueButton\Responses\GetRecordingsResponse;
39
use BigBlueButton\Responses\IsMeetingRunningResponse;
40
use BigBlueButton\Responses\JoinMeetingResponse;
41
use BigBlueButton\Responses\PublishRecordingsResponse;
42
use BigBlueButton\Responses\UpdateRecordingsResponse;
43
use BigBlueButton\Util\UrlBuilder;
44
use SimpleXMLElement;
45
46
/**
47
 * Class BigBlueButton
48
 * @package BigBlueButton
49
 */
50
class BigBlueButton
51
{
52
    private $securitySalt;
53
    private $bbbServerBaseUrl;
54
    private $urlBuilder;
55
56
    public function __construct()
57
    {
58
        $this->securitySalt     = getenv('BBB_SECURITY_SALT');
59
        $this->bbbServerBaseUrl = getenv('BBB_SERVER_BASE_URL');
60
        $this->urlBuilder       = new UrlBuilder($this->securitySalt, $this->bbbServerBaseUrl);
61
    }
62
63
    /**
64
     * @return ApiVersionResponse
65
     *
66
     * @throws \RuntimeException
67
     */
68
    public function getApiVersion()
69
    {
70
        return new ApiVersionResponse($this->processXmlResponse($this->urlBuilder->buildUrl()));
0 ignored issues
show
Bug introduced by
It seems like $this->processXmlRespons...urlBuilder->buildUrl()) can be null; however, __construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
71
    }
72
73
    /* __________________ BBB ADMINISTRATION METHODS _________________ */
74
    /* The methods in the following section support the following categories of the BBB API:
75
    -- create
76
    -- getDefaultConfigXML
77
    -- join
78
    -- end
79
    */
80
81
    /**
82
     * @param  CreateMeetingParameters $createMeetingParams
83
     * @return string
84
     */
85
    public function getCreateMeetingUrl($createMeetingParams)
86
    {
87
        return $this->urlBuilder->buildUrl(ApiMethod::CREATE, $createMeetingParams->getHTTPQuery());
88
    }
89
90
    /**
91
     * @param  CreateMeetingParameters $createMeetingParams
92
     * @return CreateMeetingResponse
93
     * @throws \RuntimeException
94
     */
95
    public function createMeeting($createMeetingParams)
96
    {
97
        $xml = $this->processXmlResponse($this->getCreateMeetingUrl($createMeetingParams), $createMeetingParams->getPresentationsAsXML());
0 ignored issues
show
Security Bug introduced by
It seems like $createMeetingParams->getPresentationsAsXML() targeting BigBlueButton\Parameters...getPresentationsAsXML() can also be of type false; however, BigBlueButton\BigBlueButton::processXmlResponse() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
98
99
        return new CreateMeetingResponse($xml);
0 ignored issues
show
Bug introduced by
It seems like $xml defined by $this->processXmlRespons...etPresentationsAsXML()) on line 97 can be null; however, BigBlueButton\Responses\...Response::__construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
100
    }
101
102
    /**
103
     * @return string
104
     */
105
    public function getDefaultConfigXMLUrl()
106
    {
107
        return $this->urlBuilder->buildUrl(ApiMethod::GET_DEFAULT_CONFIG_XML);
108
    }
109
110
    /**
111
     * @return GetDefaultConfigXMLResponse
112
     * @throws \RuntimeException
113
     */
114
    public function getDefaultConfigXML()
115
    {
116
        $xml = $this->processXmlResponse($this->getDefaultConfigXMLUrl());
117
118
        return new GetDefaultConfigXMLResponse($xml);
0 ignored issues
show
Bug introduced by
It seems like $xml defined by $this->processXmlRespons...tDefaultConfigXMLUrl()) on line 116 can be null; however, BigBlueButton\Responses\...Response::__construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
119
    }
120
121
    /**
122
     * @param $joinMeetingParams JoinMeetingParameters
123
     *
124
     * @return string
125
     */
126
    public function getJoinMeetingURL($joinMeetingParams)
127
    {
128
        return $this->urlBuilder->buildUrl(ApiMethod::JOIN, $joinMeetingParams->getHTTPQuery());
129
    }
130
131
    /**
132
     * @param $joinMeetingParams JoinMeetingParameters
133
     *
134
     * @return JoinMeetingResponse
135
     * @throws \RuntimeException
136
     */
137
    public function joinMeeting($joinMeetingParams)
138
    {
139
        $xml = $this->processXmlResponse($this->getJoinMeetingURL($joinMeetingParams));
140
141
        return new JoinMeetingResponse($xml);
0 ignored issues
show
Bug introduced by
It seems like $xml defined by $this->processXmlRespons...RL($joinMeetingParams)) on line 139 can be null; however, BigBlueButton\Responses\...Response::__construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
142
    }
143
144
    /**
145
     * @param $endParams EndMeetingParameters
146
     *
147
     * @return string
148
     */
149
    public function getEndMeetingURL($endParams)
150
    {
151
        return $this->urlBuilder->buildUrl(ApiMethod::END, $endParams->getHTTPQuery());
152
    }
153
154
    /**
155
     * @param $endParams EndMeetingParameters
156
     *
157
     * @return EndMeetingResponse
158
     * @throws \RuntimeException
159
     * */
160
    public function endMeeting($endParams)
161
    {
162
        $xml = $this->processXmlResponse($this->getEndMeetingURL($endParams));
163
164
        return new EndMeetingResponse($xml);
0 ignored issues
show
Bug introduced by
It seems like $xml defined by $this->processXmlRespons...MeetingURL($endParams)) on line 162 can be null; however, BigBlueButton\Responses\...Response::__construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
165
    }
166
167
    /* __________________ BBB MONITORING METHODS _________________ */
168
    /* The methods in the following section support the following categories of the BBB API:
169
    -- isMeetingRunning
170
    -- getMeetings
171
    -- getMeetingInfo
172
    */
173
174
    /**
175
     * @param $meetingParams IsMeetingRunningParameters
176
     * @return string
177
     */
178
    public function getIsMeetingRunningUrl($meetingParams)
179
    {
180
        return $this->urlBuilder->buildUrl(ApiMethod::IS_MEETING_RUNNING, $meetingParams->getHTTPQuery());
181
    }
182
183
    /**
184
     * @param $meetingParams
185
     * @return IsMeetingRunningResponse
186
     * @throws \RuntimeException
187
     */
188
    public function isMeetingRunning($meetingParams)
189
    {
190
        $xml = $this->processXmlResponse($this->getIsMeetingRunningUrl($meetingParams));
191
192
        return new IsMeetingRunningResponse($xml);
0 ignored issues
show
Bug introduced by
It seems like $xml defined by $this->processXmlRespons...ingUrl($meetingParams)) on line 190 can be null; however, BigBlueButton\Responses\...Response::__construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
193
    }
194
195
    /**
196
     * @return string
197
     */
198
    public function getMeetingsUrl()
199
    {
200
        return $this->urlBuilder->buildUrl(ApiMethod::GET_MEETINGS);
201
    }
202
203
    /**
204
     * @return GetMeetingsResponse
205
     * @throws \RuntimeException
206
     */
207
    public function getMeetings()
208
    {
209
        $xml = $this->processXmlResponse($this->getMeetingsUrl());
210
211
        return new GetMeetingsResponse($xml);
0 ignored issues
show
Bug introduced by
It seems like $xml defined by $this->processXmlRespons...this->getMeetingsUrl()) on line 209 can be null; however, BigBlueButton\Responses\...Response::__construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
212
    }
213
214
    /**
215
     * @param $meetingParams GetMeetingInfoParameters
216
     * @return string
217
     */
218
    public function getMeetingInfoUrl($meetingParams)
219
    {
220
        return $this->urlBuilder->buildUrl(ApiMethod::GET_MEETING_INFO, $meetingParams->getHTTPQuery());
221
    }
222
223
    /**
224
     * @param $meetingParams GetMeetingInfoParameters
225
     * @return GetMeetingInfoResponse
226
     * @throws \RuntimeException
227
     */
228
    public function getMeetingInfo($meetingParams)
229
    {
230
        $xml = $this->processXmlResponse($this->getMeetingInfoUrl($meetingParams));
231
232
        return new GetMeetingInfoResponse($xml);
0 ignored issues
show
Bug introduced by
It seems like $xml defined by $this->processXmlRespons...nfoUrl($meetingParams)) on line 230 can be null; however, BigBlueButton\Responses\...Response::__construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
233
    }
234
235
    /* __________________ BBB RECORDING METHODS _________________ */
236
    /* The methods in the following section support the following categories of the BBB API:
237
    -- getRecordings
238
    -- publishRecordings
239
    -- deleteRecordings
240
    */
241
242
    /**
243
     * @param $recordingsParams GetRecordingsParameters
244
     * @return string
245
     */
246
    public function getRecordingsUrl($recordingsParams)
247
    {
248
        return $this->urlBuilder->buildUrl(ApiMethod::GET_RECORDINGS, $recordingsParams->getHTTPQuery());
249
    }
250
251
    /**
252
     * @param $recordingParams
253
     * @return GetRecordingsResponse
254
     * @throws \RuntimeException
255
     */
256
    public function getRecordings($recordingParams)
257
    {
258
        $xml = $this->processXmlResponse($this->getRecordingsUrl($recordingParams));
259
260
        return new GetRecordingsResponse($xml);
0 ignored issues
show
Bug introduced by
It seems like $xml defined by $this->processXmlRespons...sUrl($recordingParams)) on line 258 can be null; however, BigBlueButton\Responses\...Response::__construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
261
    }
262
263
    /**
264
     * @param $recordingParams PublishRecordingsParameters
265
     * @return string
266
     */
267
    public function getPublishRecordingsUrl($recordingParams)
268
    {
269
        return $this->urlBuilder->buildUrl(ApiMethod::PUBLISH_RECORDINGS, $recordingParams->getHTTPQuery());
270
    }
271
272
    /**
273
     * @param $recordingParams PublishRecordingsParameters
274
     * @return PublishRecordingsResponse
275
     * @throws \RuntimeException
276
     */
277
    public function publishRecordings($recordingParams)
278
    {
279
        $xml = $this->processXmlResponse($this->getPublishRecordingsUrl($recordingParams));
280
281
        return new PublishRecordingsResponse($xml);
0 ignored issues
show
Bug introduced by
It seems like $xml defined by $this->processXmlRespons...sUrl($recordingParams)) on line 279 can be null; however, BigBlueButton\Responses\...Response::__construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
282
    }
283
284
    /**
285
     * @param $recordingParams DeleteRecordingsParameters
286
     * @return string
287
     */
288
    public function getDeleteRecordingsUrl($recordingParams)
289
    {
290
        return $this->urlBuilder->buildUrl(ApiMethod::DELETE_RECORDINGS, $recordingParams->getHTTPQuery());
291
    }
292
293
    /**
294
     * @param $recordingParams DeleteRecordingsParameters
295
     * @return DeleteRecordingsResponse
296
     * @throws \RuntimeException
297
     */
298
    public function deleteRecordings($recordingParams)
299
    {
300
        $xml = $this->processXmlResponse($this->getDeleteRecordingsUrl($recordingParams));
301
302
        return new DeleteRecordingsResponse($xml);
0 ignored issues
show
Bug introduced by
It seems like $xml defined by $this->processXmlRespons...sUrl($recordingParams)) on line 300 can be null; however, BigBlueButton\Responses\...Response::__construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
303
    }
304
305
    /**
306
     * @param $recordingParams UpdateRecordingsParameters
307
     * @return string
308
     */
309
    public function getUpdateRecordingsUrl($recordingParams)
310
    {
311
        return $this->urlBuilder->buildUrl(ApiMethod::UPDATE_RECORDINGS, $recordingParams->getHTTPQuery());
312
    }
313
314
    /**
315
     * @param $recordingParams UpdateRecordingsParameters
316
     * @return UpdateRecordingsResponse
317
     * @throws \RuntimeException
318
     */
319
    public function updateRecordings($recordingParams)
320
    {
321
        $xml = $this->processXmlResponse($this->getUpdateRecordingsUrl($recordingParams));
322
323
        return new UpdateRecordingsResponse($xml);
0 ignored issues
show
Bug introduced by
It seems like $xml defined by $this->processXmlRespons...sUrl($recordingParams)) on line 321 can be null; however, BigBlueButton\Responses\...Response::__construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
324
    }
325
326
    /* ____________________ INTERNAL CLASS METHODS ___________________ */
327
328
    /**
329
     * A private utility method used by other public methods to process XML responses.
330
     *
331
     * @param  string            $url
332
     * @param  string            $xml
333
     * @return SimpleXMLElement
334
     * @throws \RuntimeException
335
     */
336
    private function processXmlResponse($url, $xml = '')
337
    {
338
        if (extension_loaded('curl')) {
339
            $ch = curl_init();
340
            if (!$ch) {
341
                throw new \RuntimeException('Unhandled curl error: ' . curl_error($ch));
342
            }
343
            $timeout = 10;
344
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
345
            curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
346
            curl_setopt($ch, CURLOPT_URL, $url);
347
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
348
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
349
            if (count($xml) !== 0) {
350
                curl_setopt($ch, CURLOPT_HEADER, 0);
351
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
352
                curl_setopt($ch, CURLOPT_POST, 1);
353
                curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
354
                curl_setopt($ch, CURLOPT_HTTPHEADER, [
355
                    'Content-type: application/xml',
356
                    'Content-length: ' . strlen($xml),
357
                ]);
358
            }
359
            $data = curl_exec($ch);
360
            if ($data === false) {
361
                throw new \RuntimeException('Unhandled curl error: ' . curl_error($ch));
362
            }
363
            curl_close($ch);
364
365
            return new SimpleXMLElement($data);
366
        }
367
        if (count($xml) !== 0) {
368
            throw new \RuntimeException('Post XML data set but curl PHP module is not installed or not enabled.');
369
        }
370
    }
371
}
372