You are here

public function WSDataService::call in Web Service Data 2.0.x

Same name and namespace in other branches
  1. 8 src/WSDataService.php \Drupal\wsdata\WSDataService::call()

Call method to make the WSCall.

File

src/WSDataService.php, line 80

Class

WSDataService
Service for processing WSData requests.

Namespace

Drupal\wsdata

Code

public function call($wscall, $method = NULL, $replacements = [], $data = NULL, $options = [], $key = NULL, $tokens = [], $cache_tag = []) {
  $this->status = [];
  if (!is_object($wscall)) {
    $wscall = $this->entity_type_manager
      ->getStorage('wscall')
      ->load($wscall);
  }
  $start = microtime(TRUE);
  $data = $wscall
    ->call($method, $replacements, $data, $options, $key, $tokens, $cache_tag);
  $end = microtime(TRUE);
  $this->status = $wscall
    ->lastCallStatus();
  if ($this->state
    ->get('wsdata_debug_mode')) {
    if (is_object($this->status['cache']['debug'])) {
      $this->status['cache']['debug'] = $this->status['cache']['debug']
        ->render();
    }
    $this->messenger
      ->addStatus(Markup::create('<pre>' . Xss::filter(print_r($this->status, TRUE)) . '</pre>'));
  }

  // Track performance information.
  $duration = $end - $start;
  $this->performance['calls']++;
  $this->performance['runtime'] += $duration;
  $this->performance['log'][] = [
    'wscall' => $wscall
      ->label(),
    'method' => $method,
    'runtime' => $duration,
    'cached' => $this->status['cache']['debug'] ?? '',
  ];
  return $data;
}