class WsConfig in Web Service Data 7
The class used for wsconfig entities
Hierarchy
- class \Entity implements EntityInterface
- class \WsConfig
Expanded class hierarchy of WsConfig
3 string references to 'WsConfig'
- wsconfig.inc in modules/
wsconfig/ plugins/ contexts/ wsconfig.inc - wsconfig_entity_info in modules/
wsconfig/ wsconfig.module - Implements hook_entity_info().
- wsdata.inc in modules/
wsconfig/ plugins/ access/ wsdata.inc
File
- modules/
wsconfig/ wsconfig.entity.inc, line 16 - Entity classes
View source
class WsConfig extends Entity {
public $connector;
public function __construct($values = array()) {
parent::__construct($values, 'wsconfig');
$this->wsconfig_type = wsconfig_type_load($this->type);
if (isset($this->wsconfig_type->data['connector']) and class_exists($this->wsconfig_type->data['connector'])) {
$this->connector = new $this->wsconfig_type->data['connector']($this->wsconfig_type
->getEndpoint());
// Configure connector with caching settings.
if ($this->connector
->supportsCaching()) {
if (is_string($this->data)) {
$data = unserialize($this->data);
}
else {
$data = $this->data;
}
$cache_default_time = isset($data['cache_default_time']) ? $data['cache_default_time'] : 0;
$cache_default_override = isset($data['cache_default_override']) ? $data['cache_default_override'] : FALSE;
$stale_cache = isset($data['stale_cache']) ? $data['stale_cache'] : FALSE;
$this->connector
->defaultCache($cache_default_time, $cache_default_override, $stale_cache);
}
}
}
/**
* Method wsconfig->setEndpoint().
* Overide's the wsconfig_type's default endpoint
*/
public function setEndpoint($endpoint) {
if (isset($this->wsconfig_type->data['connector']) and class_exists($this->wsconfig_type->data['connector'])) {
$this->wsconfig_type
->setEndpoint($endpoint);
$this->connector = new $this->wsconfig_type->data['connector']($endpoint);
return TRUE;
}
return FALSE;
}
/**
* Method wsconfig->getEndpoint().
*/
public function getEndpoint() {
if (isset($this->connector) and is_object($this->connector)) {
return $this->connector
->getEndpoint();
}
return FALSE;
}
/**
* Get the currently configured language plugin and its settings
*/
public function getLanguagePlugin() {
$plugin = $this->wsconfig_type
->getEnabledLanguagePlugin();
if (!empty($plugin)) {
return $plugin;
}
return FALSE;
}
/**
* Method for calling a webservice method.
*
* @param string $type
* Name of the type of call. Generally "CRUD" but could include other methods
* @param array $replacements [optional]
* Replacements values for placeholders in the request URI
* @param array $argument [optional]
* Payload data for POST requests. Ex: body => 'body data'
* @param array $options [optional]
* Options to pass to the connector. Ex: header data, special triggers.
* See the documentation for your given connector
* @see http://drupal.org/project/restclient
* @param string $string [reference]
* Reference to the URL which was called
* @return array
* Returns the result of the method call.
*/
public function call($type, $replacement = array(), $argument = array(), $options = array(), &$method = '') {
if ($this->wsconfig_type
->isDisabled()) {
return FALSE;
}
if (isset($this->data['options'][$this
->getMethodKey($type)]) and is_array($this->data['options'][$this
->getMethodKey($type)])) {
$options += $this->data['options'][$this
->getMethodKey($type)];
}
// Pass a reference to the config to the connector
$options['wsconfig'] = $this;
if (isset($this->wsconfig_type->data['language always']) and $this->wsconfig_type->data['language always'] and empty($options['language'])) {
global $language;
$options['language'] = $language->language;
}
// Add the language handling if a language was requested
if (!empty($options['language'])) {
$plugin = $this
->getLanguagePlugin();
$options['language plugin'] = $plugin;
}
$replacements = $this
->getReplacements($type);
$method = $this
->getMethod($type, $replacement);
$matches = array();
preg_match_all("/(%[a-zA-Z0-9]+)/", $method, $matches);
// Compare the tokens extracted to see if some haven't been replaced.
if (sizeof($matches[0])) {
foreach ($matches[0] as $match) {
if (in_array($match, $replacements)) {
throw new WsConfigException(t('Replacement tokens not all replaced before wscall: @tokens', array(
'@tokens' => implode(',', $matches[0]),
)));
}
}
}
$start_time = microtime(true);
$result = FALSE;
if (isset($this->connector)) {
$result = $this->connector
->wscall($type, $method, $argument, $options);
}
if ($result === FALSE and isset($this->connector) and $this->connector
->isDegraded()) {
$this->wsconfig_type
->disable(TRUE);
}
if (module_exists('ws_performance')) {
$run_time = round((microtime(true) - $start_time) * 1000);
ws_performance_record_performance($this, $type, $method, $run_time, array(
'replacement' => $replacement,
'arguments' => $argument,
'options' => $options,
), $result);
}
return $result;
}
/**
* Get a list of defined methods.
*/
public function getMethod($type, $replacement = array()) {
if (!isset($this->data[$type . '_data_method'])) {
return FALSE;
}
$method = $this->data[$type . '_data_method'];
foreach ($replacement as $token => $replace) {
$method = str_replace($token, $replace, $method);
}
return $method;
}
public function getReplacements($type) {
if (!isset($this->data[$type . '_data_method'])) {
return FALSE;
}
$method = $this->data[$type . '_data_method'];
$matches = array();
preg_match_all("/(%\\w+)/", $method, $matches);
return $matches[0];
}
public function getOperations() {
$ops = array();
foreach ($this->data as $key => $val) {
if (drupal_substr($key, -1 * drupal_strlen('_data_method')) == '_data_method') {
$ops[] = drupal_substr($key, 0, -1 * drupal_strlen('_data_method'));
}
}
if (empty($ops)) {
return array();
}
return $ops;
}
public function addMethod($type, $name = '') {
$methods = $this
->getPossibleMethods();
if (!isset($methods[$type])) {
return FALSE;
}
$methodname = $type;
$supported = $this->connector
->getMethods();
if (isset($supported['multiple'][$type])) {
$name = drupal_strtolower(preg_replace('/\\W/', '', $name));
if (empty($name)) {
return FALSE;
}
$methodname .= '_' . $name;
}
$this->data[$this
->getMethodKey($methodname)] = '';
return TRUE;
}
public function getPossibleMethods() {
$supported = $this->connector
->getMethods();
$methods = array_merge($supported['single'], $supported['multiple']);
foreach ($this
->getOperations() as $op) {
if (isset($supported['single'][$op])) {
unset($methods[$op]);
}
}
return $methods;
}
public function getMethodKey($operation) {
return $operation . '_data_method';
}
public function getMethodName($operation) {
$supported = $this->connector
->getMethods();
foreach ($supported['multiple'] as $key => $val) {
if (drupal_substr($operation, 0, drupal_strlen($key) + 1) == $key . '_') {
$operation = ucfirst($key) . ': ' . ucfirst(drupal_substr($operation, drupal_strlen($key) + 1));
return $operation;
}
}
return ucfirst($operation);
}
protected function defaultLabel() {
return $this->title;
}
protected function defaultUri() {
return array(
'path' => 'wsconfig/' . $this->name,
);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Entity:: |
protected | property | 1 | |
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
public | function |
Builds a structured array representing the entity's content. Overrides EntityInterface:: |
1 |
Entity:: |
public | function |
Returns the bundle of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Permanently deletes the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the info of the type of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the type of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Exports the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Gets the raw, translated value of a property or field. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Checks if the entity has a certain exportable status. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the entity identifier, i.e. the entities name or numeric id. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the internal, numeric identifier. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Checks whether the entity is the default revision. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the label of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Permanently saves the entity. Overrides EntityInterface:: |
|
Entity:: |
protected | function | Set up the object instance on construction or unserializiation. | |
Entity:: |
public | function |
Returns the uri of the entity just as entity_uri(). Overrides EntityInterface:: |
|
Entity:: |
public | function |
Generate an array for rendering the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the EntityMetadataWrapper of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function | Magic method to only serialize what's necessary. | |
Entity:: |
public | function | Magic method to invoke setUp() on unserialization. | |
WsConfig:: |
public | property | ||
WsConfig:: |
public | function | ||
WsConfig:: |
public | function | Method for calling a webservice method. | |
WsConfig:: |
protected | function |
Defines the entity label if the 'entity_class_label' callback is used. Overrides Entity:: |
|
WsConfig:: |
protected | function |
Override this in order to implement a custom default URI and specify
'entity_class_uri' as 'uri callback' hook_entity_info(). Overrides Entity:: |
|
WsConfig:: |
public | function | Method wsconfig->getEndpoint(). | |
WsConfig:: |
public | function | Get the currently configured language plugin and its settings | |
WsConfig:: |
public | function | Get a list of defined methods. | |
WsConfig:: |
public | function | ||
WsConfig:: |
public | function | ||
WsConfig:: |
public | function | ||
WsConfig:: |
public | function | ||
WsConfig:: |
public | function | ||
WsConfig:: |
public | function | Method wsconfig->setEndpoint(). Overide's the wsconfig_type's default endpoint | |
WsConfig:: |
public | function |
Overrides Entity:: |