You are here

protected function Soap::openSourceUrl in Migrate Plus 8.3

Same name and namespace in other branches
  1. 8.5 src/Plugin/migrate_plus/data_parser/Soap.php \Drupal\migrate_plus\Plugin\migrate_plus\data_parser\Soap::openSourceUrl()
  2. 8.2 src/Plugin/migrate_plus/data_parser/Soap.php \Drupal\migrate_plus\Plugin\migrate_plus\data_parser\Soap::openSourceUrl()
  3. 8.4 src/Plugin/migrate_plus/data_parser/Soap.php \Drupal\migrate_plus\Plugin\migrate_plus\data_parser\Soap::openSourceUrl()

Throws

\SoapFault If there's an error in a SOAP call.

\Drupal\migrate\MigrateException If we can't resolve the SOAP function or its response property.

Overrides DataParserPluginBase::openSourceUrl

File

src/Plugin/migrate_plus/data_parser/Soap.php, line 65

Class

Soap
Obtain SOAP data for migration.

Namespace

Drupal\migrate_plus\Plugin\migrate_plus\data_parser

Code

protected function openSourceUrl($url) {

  // Will throw SoapFault if there's
  $client = new \SoapClient($url);

  // Determine the response property name.
  $function_found = FALSE;
  foreach ($client
    ->__getFunctions() as $function_signature) {

    // E.g., "GetWeatherResponse GetWeather(GetWeather $parameters)".
    $response_type = strtok($function_signature, ' ');
    $function_name = strtok('(');
    if (strcasecmp($function_name, $this->function) === 0) {
      $function_found = TRUE;
      foreach ($client
        ->__getTypes() as $type_info) {

        // E.g., "struct GetWeatherResponse {\n string GetWeatherResult;\n}".
        if (preg_match('|struct (.*?) {\\s*[a-z]+ (.*?);|is', $type_info, $matches)) {
          if ($matches[1] == $response_type) {
            $response_property = $matches[2];
          }
        }
      }
      break;
    }
  }
  if (!$function_found) {
    throw new MigrateException("SOAP function {$this->function} not found.");
  }
  elseif (!isset($response_property)) {
    throw new MigrateException("Response property not found for SOAP function {$this->function}.");
  }
  $response = $client
    ->{$this->function}($this->parameters);
  $response_value = $response->{$response_property};
  switch ($this->responseType) {
    case 'xml':
      $xml = simplexml_load_string($response_value);
      $this->iterator = new \ArrayIterator($xml
        ->xpath($this->itemSelector));
      break;
    case 'object':
      $this->iterator = new \ArrayIterator($response_value->{$this->itemSelector});
      break;
    case 'array':
      $this->iterator = new \ArrayIterator($response_value[$this->itemSelector]);
      break;
  }
  return TRUE;
}