public function WSClientRESTEndpoint::client in Web service client 7
Return value
HttpClient
1 call to WSClientRESTEndpoint::client()
- WSClientRESTEndpoint::call in wsclient_rest/wsclient_rest.inc
- Calls the REST service.
File
- wsclient_rest/wsclient_rest.inc, line 27
- Web service client REST - include file.
Class
- WSClientRESTEndpoint
- A remote endpoint type for invoking REST services.
Code
public function client() {
if (!isset($this->client)) {
$settings = $this->service->settings;
$authentication = NULL;
if (isset($settings['authentication'])) {
foreach ($settings['authentication'] as $auth => $auth_settings) {
if ($auth == 'type') {
continue;
}
if ($auth == $settings['authentication']['type']) {
switch ($auth) {
case 'oauth2':
$authentication = new HttpClientOAuth2($auth_settings);
break;
case 'basic':
case 'wss':
default:
$username = $auth_settings['username'];
$password = $auth_settings['password'];
$authentication = new HttpClientBasicAuth($username, $password);
break;
}
}
}
}
if (wsclient_rest_has_old_formatter($settings)) {
$formatter = new $settings['formatter']();
$this->client = new HttpClient($authentication, $formatter, $this);
}
else {
$formatters = array();
foreach (array(
'send_formatter',
'receive_formatter',
) as $formatter_type) {
$formatter_settings = !empty($settings[$formatter_type]['settings']) ? $settings[$formatter_type]['settings'] : array();
$formatters[$formatter_type] = new $settings[$formatter_type]['class']($formatter_settings);
}
$formatter = new HttpClientCompositeFormatter($formatters['send_formatter'], $formatters['receive_formatter']);
$this->client = new HttpClient($authentication, $formatter, $this);
}
if (!empty($settings['curl options'])) {
$this->client->options['curlopts'] = $settings['curl options'];
}
}
return $this->client;
}