|
@@ -90,10 +90,11 @@ class Webservice
|
|
* @param string $url
|
|
* @param string $url
|
|
* @param string $method
|
|
* @param string $method
|
|
* @param array $data
|
|
* @param array $data
|
|
|
|
+ * @param int $timeout
|
|
*
|
|
*
|
|
* @return HttpResponse
|
|
* @return HttpResponse
|
|
*/
|
|
*/
|
|
- public function makeRequest($url, $method = HttpRequestInterface::METHOD_GET, $data = array())
|
|
|
|
|
|
+ public function makeRequest($url, $method = HttpRequestInterface::METHOD_GET, $data = array(), $timeout = 60)
|
|
{
|
|
{
|
|
try {
|
|
try {
|
|
$request = new HttpRequest($method, $url);
|
|
$request = new HttpRequest($method, $url);
|
|
@@ -104,6 +105,7 @@ class Webservice
|
|
}
|
|
}
|
|
$request->setHeaders($headers);
|
|
$request->setHeaders($headers);
|
|
$response = new HttpResponse();
|
|
$response = new HttpResponse();
|
|
|
|
+ $this->httpClient->setTimeout($timeout);
|
|
$this->httpClient->send($request, $response);
|
|
$this->httpClient->send($request, $response);
|
|
$response = $response->getContent();
|
|
$response = $response->getContent();
|
|
} catch (RequestException $ex) {
|
|
} catch (RequestException $ex) {
|
|
@@ -120,10 +122,11 @@ class Webservice
|
|
* @param array $data
|
|
* @param array $data
|
|
* @param array $credentials
|
|
* @param array $credentials
|
|
* @param array $cookies
|
|
* @param array $cookies
|
|
|
|
+ * @param int $timeout
|
|
*
|
|
*
|
|
* @return HttpResponse
|
|
* @return HttpResponse
|
|
*/
|
|
*/
|
|
- public function makeGetRequest($url, $method = HttpRequestInterface::METHOD_GET, $data = array(), $credentials = array(), $cookies = array())
|
|
|
|
|
|
+ public function makeGetRequest($url, $method = HttpRequestInterface::METHOD_GET, $data = array(), $credentials = array(), $cookies = array(), $timeout = 60)
|
|
{
|
|
{
|
|
try {
|
|
try {
|
|
$headers = array();
|
|
$headers = array();
|
|
@@ -133,7 +136,7 @@ class Webservice
|
|
} elseif (!empty($credentials) && isset($credentials['username']) && isset($credentials['password'])) {
|
|
} elseif (!empty($credentials) && isset($credentials['username']) && isset($credentials['password'])) {
|
|
$headers[] = 'Authorization: Basic ' . base64_encode($credentials['username'] . ":" . $credentials['password']);
|
|
$headers[] = 'Authorization: Basic ' . base64_encode($credentials['username'] . ":" . $credentials['password']);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
foreach ($cookies as $cookie => $value) {
|
|
foreach ($cookies as $cookie => $value) {
|
|
$headers[] = "Cookie: {$cookie}={$value}";
|
|
$headers[] = "Cookie: {$cookie}={$value}";
|
|
}
|
|
}
|
|
@@ -145,6 +148,7 @@ class Webservice
|
|
}
|
|
}
|
|
$request->setHeaders($headers);
|
|
$request->setHeaders($headers);
|
|
$response = new HttpResponse();
|
|
$response = new HttpResponse();
|
|
|
|
+ $this->httpClient->setTimeout($timeout);
|
|
$this->httpClient->send($request, $response);
|
|
$this->httpClient->send($request, $response);
|
|
$response = $response->getContent();
|
|
$response = $response->getContent();
|
|
} catch (RequestException $ex) {
|
|
} catch (RequestException $ex) {
|
|
@@ -255,7 +259,7 @@ class Webservice
|
|
$result = $this->getArray($webservice, array(
|
|
$result = $this->getArray($webservice, array(
|
|
'id' => $id,
|
|
'id' => $id,
|
|
));
|
|
));
|
|
-
|
|
|
|
|
|
+
|
|
$isset = isset($result[0]) && isset($result[0]['id']) && isset($result[0]['externalId']) && isset($result[0]['name']);
|
|
$isset = isset($result[0]) && isset($result[0]['id']) && isset($result[0]['externalId']) && isset($result[0]['name']);
|
|
return $isset
|
|
return $isset
|
|
? "{$result[0]['externalId']} - {$result[0]['name']} ({$result[0]['id']})"
|
|
? "{$result[0]['externalId']} - {$result[0]['name']} ({$result[0]['id']})"
|