You are here

public function FeedImportUniVectorReader::map in Feed Import 8

Returns a value mapped from obj by path.

Parameters

mixed $obj Variable to search:

mixed $path Path to value:

Return value

mixed Mapped value

Overrides FeedImportReader::map

File

feed_import_base/src/FeedImportUniVectorReader.php, line 13

Class

FeedImportUniVectorReader
This class is a helper for unidimensional vector reader. This can be used for CSV, SQL results, etc.

Namespace

Drupal\feed_import_base

Code

public function map(&$vector, &$path) {
  if (is_array($vector)) {
    $count = 0;
    $ret = array();
    foreach ($path as $p) {
      if (isset($vector[$p])) {
        $ret[] = $vector[$p];
        $count++;
      }
    }
    return $count == 0 ? NULL : ($count == 1 ? $ret[0] : $ret);
  }
  elseif (is_object($vector)) {
    $count = 0;
    $ret = array();
    foreach ($path as $p) {
      if (isset($vector->{$p})) {
        $ret[] = $vector->{$p};
        $count++;
      }
    }
    return $count == 0 ? NULL : ($count == 1 ? $ret[0] : $ret);
  }
  return NULL;
}