You are here

public function FeedImportDomXPathReader::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/FeedImportDomXPathReader.php, line 18

Class

FeedImportDomXPathReader
This class provides a helper for dom xpath queries.

Namespace

Drupal\feed_import_base

Code

public function map(&$item, &$path) {
  $values = $this->xpath
    ->evaluate($path, $item, $this->xpathRegisterNodeNS);
  if ($values instanceof DOMNodeList) {
    if (!($len = $values->length)) {
      return NULL;
    }
    elseif ($len == 1) {
      return $values
        ->item(0)->nodeValue;
    }
    $i = 0;
    $ret = array();
    while ($i < $len) {
      $ret[] = $values
        ->item($i++)->nodeValue;
    }
    return $ret;
  }
  return $values;
}