class WSConnectorLocalFile in Web Service Data 2.0.x
Same name and namespace in other branches
- 8 src/Plugin/WSConnector/WSConnectorLocalFile.php \Drupal\wsdata\Plugin\WSConnector\WSConnectorLocalFile
Local file connector.
Plugin annotation
@WSConnector(
id = "WSConnectorLocalFile",
label = @Translation("Local file 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\WSConnectorLocalFile
- class \Drupal\wsdata\Plugin\WSConnectorBase implements WSConnectorInterface uses StringTranslationTrait
Expanded class hierarchy of WSConnectorLocalFile
File
- src/
Plugin/ WSConnector/ WSConnectorLocalFile.php, line 15
Namespace
Drupal\wsdata\Plugin\WSConnectorView source
class WSConnectorLocalFile extends WSConnectorBase {
/**
* {@inheritdoc}
*/
public function getMethods() {
return [
'read',
'write',
'append',
];
}
/**
* {@inheritdoc}
*/
public function getOptions() {
return [
'filename' => NULL,
'readonly' => TRUE,
];
}
/**
* {@inheritdoc}
*/
public function getOptionsForm($options = []) {
return [
'filename' => [
'#title' => $this
->t('Filename'),
'#type' => 'textfield',
],
'readonly' => [
'#title' => $this
->t('Prevent writing to this file.'),
'#type' => 'checkbox',
],
];
}
/**
* {@inheritdoc}
*/
public function getReplacements(array $options) {
return $this
->findTokens($this->endpoint . '/' . $options['filename']);
}
/**
* {@inheritdoc}
*/
public function call($options, $method, $replacements = [], $data = NULL, array $tokens = []) {
$filename = $this->endpoint . '/' . $options['filename'];
$filename = $this
->applyReplacements($filename, $replacements, $tokens);
$flags = 0;
switch ($method) {
case 'append':
$flags = FILE_APPEND;
case 'write':
if (!is_writable($filename)) {
$this
->setError(1, $this
->t('%filename is not writable.', [
'%filename' => $filename,
]));
return FALSE;
}
return file_put_contents($filename, $data, $flags);
case 'read':
default:
if (!file_exists($filename)) {
$this
->setError(1, $this
->t('%filename does not exist.', [
'%filename' => $filename,
]));
return FALSE;
}
if (!is_readable($filename)) {
$this
->setError(1, $this
->t('%filename is not readable.', [
'%filename' => $filename,
]));
return FALSE;
}
return file_get_contents($filename);
}
}
}
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 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:: |
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 |
WSConnectorLocalFile:: |
public | function |
Make the connector call. Overrides WSConnectorBase:: |
|
WSConnectorLocalFile:: |
public | function |
Return available methods supported by the connector. Overrides WSConnectorBase:: |
|
WSConnectorLocalFile:: |
public | function |
Return available options supported by the connector. Overrides WSConnectorBase:: |
|
WSConnectorLocalFile:: |
public | function |
Return the settings form provided by the connector. Overrides WSConnectorBase:: |
|
WSConnectorLocalFile:: |
public | function |
Return an array of replacements. Overrides WSConnectorBase:: |