abstract class WSConnectorBase in Web Service Data 2.0.x
Same name and namespace in other branches
- 8 src/Plugin/WSConnectorBase.php \Drupal\wsdata\Plugin\WSConnectorBase
Base class for Wsconnector plugin plugins.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\wsdata\Plugin\WSConnectorBase implements WSConnectorInterface uses StringTranslationTrait
Expanded class hierarchy of WSConnectorBase
3 files declare their use of WSConnectorBase
- WSConnectorLocalFile.php in src/
Plugin/ WSConnector/ WSConnectorLocalFile.php - WSConnectorSimpleHTTP.php in src/
Plugin/ WSConnector/ WSConnectorSimpleHTTP.php - WSConnectorSOAP.php in src/
Plugin/ WSConnector/ WSConnectorSOAP.php
File
- src/
Plugin/ WSConnectorBase.php, line 13
Namespace
Drupal\wsdata\PluginView source
abstract class WSConnectorBase extends PluginBase implements WSConnectorInterface {
use StringTranslationTrait;
protected $expires;
protected $cacheDefaultTime;
protected $cacheDefaultOverride;
protected $staleCache;
protected $endpoint;
protected $error;
protected $status;
protected $languagePlugins = [
'default',
];
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, Token $token) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->token = $token;
$this->expires = 0;
$this->cacheDefaultTime = 0;
$this->cacheDefaultOverride = FALSE;
$this->staleCache = FALSE;
$this->status = [];
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('token'));
}
/**
* Return available options supported by the connector.
*/
public abstract function getOptions();
/**
* Return available methods supported by the connector.
*/
public abstract function getMethods();
/**
* Return an array of replacements.
*/
public abstract function getReplacements(array $options);
/**
* Return the settings form provided by the connector.
*/
public function getOptionsForm($options = []) {
return [];
}
/**
* Return cache cid for cases cache rules change.
*/
public function getCache() {
return NULL;
}
/**
* Make the connector call.
*/
public abstract function call($options, $method, $replacements = [], $data = NULL, array $tokens = []);
/**
* Setter for the endpoint.
*/
public function setEndpoint($endpoint) {
$this->endpoint = trim($endpoint);
}
/**
* Getter for the endpoint.
*/
public function getEndpoint() {
return $this->endpoint;
}
/**
* Whether returned data can be cached.
*/
public function supportsCaching($method = NULL) {
return FALSE;
}
/**
* Return the last error the connector received.
*/
public function getError() {
return $this->error;
}
/**
* Return the status of the last call.
*/
public function getStatus() {
return $this->status;
}
/**
* Return the list of supported language handling plugins.
*/
public function getSupportedLanguagePlugins() {
return $this->languagePlugins;
}
/**
* Figure out the overrides for cache times.
*/
public function defaultCache($mintime = 0, $override = FALSE, $stale = FALSE) {
$this->cacheDefaultTime = $mintime;
$this->cacheDefaultOverride = $override;
$this->staleCache = $stale;
}
/**
* Get the expired time for caching.
*/
public function expires() {
if ($this->expires > 0) {
return $this->expires;
}
else {
return FALSE;
}
}
/**
* Whether the connector is in a dead state and shouldn't be called.
*/
public function isDegraded() {
return FALSE;
}
/**
* Setter for the connector errors.
*/
protected function setError($code, $message) {
$this->error = [
'code' => $code,
'message' => $message,
];
}
/**
* Clear current error.
*/
protected function clearError() {
$this->error = NULL;
}
/**
* Saves the options form.
*/
public function saveOptions($values) {
$options = [];
foreach (array_keys($this
->getOptionsForm()) as $option) {
if (isset($values[$option])) {
$options[$option] = $values[$option];
}
}
return $options;
}
/**
* Internal function for finding tokens.
*/
protected function findTokens($string) {
preg_match_all('/\\[([\\w:]+)\\]/', $string, $matches);
return $matches[1];
}
/**
* Internal function for applying replacements.
*/
protected function applyReplacements($string, array $replacements = [], array $tokens = []) {
foreach ($replacements as $token => $replace) {
$string = str_replace('[' . $token . ']', $replace, $string);
}
$string = $this->token
->replace($string, $tokens);
return $string;
}
}
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:: |
abstract public | function | Make the connector call. | 2 |
WSConnectorBase:: |
protected | function | Clear current error. | |
WSConnectorBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
1 |
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:: |
abstract public | function | Return available methods supported by the connector. | 2 |
WSConnectorBase:: |
abstract public | function | Return available options supported by the connector. | 2 |
WSConnectorBase:: |
public | function |
Return the settings form provided by the connector. Overrides WSConnectorInterface:: |
2 |
WSConnectorBase:: |
abstract public | function | Return an array of replacements. | 2 |
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 | Saves the options form. | 1 |
WSConnectorBase:: |
public | function | Setter for the endpoint. | |
WSConnectorBase:: |
protected | function | Setter for the connector errors. | |
WSConnectorBase:: |
public | function | Whether returned data can be cached. | 1 |
WSConnectorBase:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
1 |