class WSConnectorSOAP in Web Service Data 2.0.x
Same name and namespace in other branches
- 8 src/Plugin/WSConnector/WSConnectorSOAP.php \Drupal\wsdata\Plugin\WSConnector\WSConnectorSOAP
REST Connector.
Plugin annotation
@WSConnector(
id = "WSConnectorSOAP",
label = @Translation("SOAP Connector", context = "WSConnector"),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\wsdata\Plugin\WSConnectorBase implements WSConnectorInterface uses StringTranslationTrait
- class \Drupal\wsdata\Plugin\WSConnector\WSConnectorSimpleHTTP
- class \Drupal\wsdata\Plugin\WSConnector\WSConnectorSOAP
- class \Drupal\wsdata\Plugin\WSConnector\WSConnectorSimpleHTTP
- class \Drupal\wsdata\Plugin\WSConnectorBase implements WSConnectorInterface uses StringTranslationTrait
Expanded class hierarchy of WSConnectorSOAP
File
- src/
Plugin/ WSConnector/ WSConnectorSOAP.php, line 17
Namespace
Drupal\wsdata\Plugin\WSConnectorView source
class WSConnectorSOAP extends WSConnectorSimpleHTTP {
/**
* {@inheritdoc}
*/
public function getMethods() {
return [
'create',
'read',
'update',
'delete',
'index',
];
}
/**
* {@inheritdoc}
*/
public function getOptions() {
return [
'path' => null,
'methods' => [],
'headers' => [],
'user' => null,
'key' => null,
];
}
/**
* {@inheritdoc}
*/
public function getReplacements(array $options) {
return $this
->findTokens($options['path']);
}
/**
* {@inheritdoc}
*/
public function getOptionsForm($options = []) {
$form['path'] = [
'#title' => $this
->t('Path'),
'#description' => $this
->t('The final endpoint will be <em>Server Endpoint/Path</em>'),
'#type' => 'textfield',
'#maxlength' => 512,
];
$form['user'] = [
'#type' => 'textfield',
'#title' => $this
->t('Username'),
'#description' => $this
->t('Authentication'),
'#required' => true,
];
$form['key'] = [
'#type' => 'textfield',
'#title' => $this
->t('Password'),
'#description' => $this
->t('Authentication'),
'#required' => true,
];
$header_count = 5;
if (isset($options['form_state'])) {
$input = $options['form_state']
->getUserInput();
if (isset($input['headers_count'])) {
$header_count = $input['headers_count'] + 1;
}
}
$form['headers'] = [
'#title' => $this
->t('Fixed Parameters'),
'#type' => 'fieldset',
'#attributes' => [
'id' => 'wsconnector-headers',
],
];
$form['headers']['headers_count'] = [
'#type' => 'hidden',
'#value' => $header_count,
];
for ($i = 0; $i < $header_count; $i++) {
$form['headers'][$i]['key_' . $i] = [
'#type' => 'textfield',
'#title' => t('Key'),
];
$form['headers'][$i]['value_' . $i] = [
'#type' => 'textfield',
'#title' => t('Value'),
];
}
if (isset($options['form_state'])) {
$form['headers']['add_another'] = [
'#type' => 'submit',
'#value' => $this
->t('Add another'),
'#ajax' => [
'callback' => '\\Drupal\\wsdata\\Plugin\\WSConnector\\WSConnectorSimpleHTTP::wsconnectorHttpHeaderAjaxCallback',
'wrapper' => 'wsconnector-headers',
],
'#limit_validation_errors' => [],
];
}
$form['wsdl'] = [
'#type' => 'textfield',
'#title' => $this
->t('WSDL'),
'#description' => $this
->t('WSDL url'),
'#required' => true,
];
$form['method'] = [
'#type' => 'textfield',
'#title' => $this
->t('Method'),
'#description' => $this
->t('Method name'),
'#required' => true,
];
return $form;
}
/**
* {@inheritdoc}
*/
public function call($options, $method, $replacements = [], $data = null, array $tokens = []) {
$token_service = \Drupal::token();
$uri = $this->endpoint . '/' . $options['path'];
// Perform the token replace on the headers.
if (!empty($options['headers'])) {
for ($i = 0; $i < count($options['headers']); $i++) {
if (!empty($options['headers'][$i]['key_' . $i])) {
$options['headers'][$options['headers'][$i]['key_' . $i]] = $token_service
->replace($options['headers'][$i]['value_' . $i], $tokens);
}
unset($options['headers'][$i]['key_' . $i]);
unset($options['headers'][$i]['value_' . $i]);
unset($options['headers'][$i]);
}
if (count($replacements) == count($replacements, COUNT_RECURSIVE)) {
$payload = array_merge($replacements, $options['headers']);
}
else {
// array is multidimensional
$payload = $replacements;
foreach ($options['headers'] as $k => $v) {
$payload[array_keys($replacements)[0]][$k] = $v;
}
}
}
if (isset($options['method']) && !empty($options['method'])) {
$method = $options['method'];
}
if (isset($options['wsdl']) && !empty($options['wsdl'])) {
$wsdl = DRUPAL_ROOT . $options['wsdl'];
}
else {
$wsdl = $uri;
}
$result = FALSE;
try {
if (isset($options["user"]) && isset($options["key"])) {
$service = new \SoapClient($wsdl, array(
'login' => $options["user"],
'password' => $options["key"],
));
}
else {
$service = new \SoapClient($wsdl);
}
if (isset($options['wsdl']) && !empty($options['wsdl']) && isset($options['path']) && !empty($options['path'])) {
$service
->__setLocation($uri);
}
if (!is_soap_fault($service)) {
$result = $service
->__soapCall($method, !empty($options['headers']) ? array(
$payload,
) : array(
$replacements,
));
}
} catch (\Throwable $th) {
$message = $this
->t('SOAP call: Could not call endpoint: :uri and method: @method', [
':uri' => $uri,
'@method' => $method,
]);
$this
->setError(1, $message);
}
return $result;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
WSConnectorBase:: |
protected | property | ||
WSConnectorBase:: |
protected | property | ||
WSConnectorBase:: |
protected | property | ||
WSConnectorBase:: |
protected | property | ||
WSConnectorBase:: |
protected | property | ||
WSConnectorBase:: |
protected | property | ||
WSConnectorBase:: |
protected | property | ||
WSConnectorBase:: |
protected | property | ||
WSConnectorBase:: |
protected | function | Internal function for applying replacements. | |
WSConnectorBase:: |
protected | function | Clear current error. | |
WSConnectorBase:: |
public | function | Figure out the overrides for cache times. | |
WSConnectorBase:: |
public | function | Get the expired time for caching. | |
WSConnectorBase:: |
protected | function | Internal function for finding tokens. | |
WSConnectorBase:: |
public | function | Return cache cid for cases cache rules change. | 2 |
WSConnectorBase:: |
public | function | Getter for the endpoint. | |
WSConnectorBase:: |
public | function | Return the last error the connector received. | |
WSConnectorBase:: |
public | function | Return the status of the last call. | |
WSConnectorBase:: |
public | function | Return the list of supported language handling plugins. | |
WSConnectorBase:: |
public | function | Whether the connector is in a dead state and shouldn't be called. | |
WSConnectorBase:: |
public | function | Setter for the endpoint. | |
WSConnectorBase:: |
protected | function | Setter for the connector errors. | |
WSConnectorSimpleHTTP:: |
public static | function |
Creates an instance of the plugin. Overrides WSConnectorBase:: |
2 |
WSConnectorSimpleHTTP:: |
public | function |
Saves the options form. Overrides WSConnectorBase:: |
|
WSConnectorSimpleHTTP:: |
public | function | Sets the expires times based on the response. | |
WSConnectorSimpleHTTP:: |
public | function |
Whether returned data can be cached. Overrides WSConnectorBase:: |
|
WSConnectorSimpleHTTP:: |
public static | function | Ajax callback function. | 1 |
WSConnectorSimpleHTTP:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides WSConnectorBase:: |
2 |
WSConnectorSOAP:: |
public | function |
Make the connector call. Overrides WSConnectorSimpleHTTP:: |
|
WSConnectorSOAP:: |
public | function |
Return available methods supported by the connector. Overrides WSConnectorSimpleHTTP:: |
|
WSConnectorSOAP:: |
public | function |
Return available options supported by the connector. Overrides WSConnectorSimpleHTTP:: |
|
WSConnectorSOAP:: |
public | function |
Return the settings form provided by the connector. Overrides WSConnectorSimpleHTTP:: |
|
WSConnectorSOAP:: |
public | function |
Return an array of replacements. Overrides WSConnectorSimpleHTTP:: |