Soap.php in Migrate Plus 8.3
File
src/Plugin/migrate_plus/data_parser/Soap.php
View source
<?php
namespace Drupal\migrate_plus\Plugin\migrate_plus\data_parser;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\MigrateException;
use Drupal\migrate_plus\DataParserPluginBase;
class Soap extends DataParserPluginBase implements ContainerFactoryPluginInterface {
protected $iterator;
protected $function;
protected $parameters;
protected $responseType;
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->function = $configuration['function'];
$this->parameters = $configuration['parameters'];
$this->responseType = $configuration['response_type'];
}
protected function openSourceUrl($url) {
$client = new \SoapClient($url);
$function_found = FALSE;
foreach ($client
->__getFunctions() as $function_signature) {
$response_type = strtok($function_signature, ' ');
$function_name = strtok('(');
if (strcasecmp($function_name, $this->function) === 0) {
$function_found = TRUE;
foreach ($client
->__getTypes() as $type_info) {
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;
}
protected function fetchNextRow() {
$current = $this->iterator
->current();
if ($current) {
foreach ($this
->fieldSelectors() as $field_name => $selector) {
$this->currentItem[$field_name] = $current->{$selector};
}
$this->iterator
->next();
}
}
}
Classes
Name |
Description |
Soap |
Obtain SOAP data for migration. |