You are here

FeedImportDomXPathReader.php in Feed Import 8

File

feed_import_base/src/FeedImportDomXPathReader.php
View source
<?php

namespace Drupal\feed_import_base;


/**
 * This class provides a helper for dom xpath queries.
 */
abstract class FeedImportDomXPathReader extends FeedImportReader {

  // DomXPath instance
  protected $xpath;

  // Bool, see DomXPath::evaluate
  protected $xpathRegisterNodeNS = TRUE;

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Classes

Namesort descending Description
FeedImportDomXPathReader This class provides a helper for dom xpath queries.