You are here

protected function Json::selectByDepth in Migrate Plus 8.5

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

Get the source data for reading.

Parameters

array $raw_data: Raw data from the JSON feed.

Return value

array Selected items at the requested depth of the JSON feed.

1 call to Json::selectByDepth()
Json::getSourceData in src/Plugin/migrate_plus/data_parser/Json.php
Retrieves the JSON data and returns it as an array.

File

src/Plugin/migrate_plus/data_parser/Json.php, line 73

Class

Json
Obtain JSON data for migration.

Namespace

Drupal\migrate_plus\Plugin\migrate_plus\data_parser

Code

protected function selectByDepth(array $raw_data) {

  // Return the results in a recursive iterator that can traverse
  // multidimensional arrays.
  $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($raw_data), \RecursiveIteratorIterator::SELF_FIRST);
  $items = [];

  // Backwards-compatibility - an integer item_selector is interpreted as a
  // depth. When there is an array of items at the expected depth, pull that
  // array out as a distinct item.
  $identifierDepth = $this->itemSelector;
  $iterator
    ->rewind();
  while ($iterator
    ->valid()) {
    $item = $iterator
      ->current();
    if (is_array($item) && $iterator
      ->getDepth() == $identifierDepth) {
      $items[] = $item;
    }
    $iterator
      ->next();
  }
  return $items;
}