You are here

public function WsConfig::call in Web Service Data 7

Method for calling a webservice method.

Parameters

string $type: Name of the type of call. Generally "CRUD" but could include other methods

array $replacements [optional]: Replacements values for placeholders in the request URI

array $argument [optional]: Payload data for POST requests. Ex: body => 'body data'

array $options [optional]: Options to pass to the connector. Ex: header data, special triggers. See the documentation for your given connector

string $string [reference]: Reference to the URL which was called

Return value

array Returns the result of the method call.

See also

http://drupal.org/project/restclient

File

modules/wsconfig/wsconfig.entity.inc, line 95
Entity classes

Class

WsConfig
The class used for wsconfig entities

Code

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;
}