You are here

abstract class FeedImportSimpleXPathReader in Feed Import 8

This class is a helper for xpath readers using SimpleXMLElement.

Hierarchy

Expanded class hierarchy of FeedImportSimpleXPathReader

File

feed_import_base/src/FeedImportSimpleXPathReader.php, line 7

Namespace

Drupal\feed_import_base
View source
abstract class FeedImportSimpleXPathReader extends FeedImportReader {

  /**
   * {@inheritdoc}
   */
  public function map(&$item, &$xpath) {

    // Get values and handle xpath exceptions.
    try {
      $values = $item
        ->xpath($xpath);
    } catch (Exception $e) {
      return NULL;
    }

    // Xpath gave no values return null.
    if (!$values) {
      return NULL;
    }

    // Get the number of values.
    $count = count($values);
    $i = -1;
    while (++$i < $count) {

      // Get each value.
      $values[$i] = (string) $values[$i][0];
    }

    // Return values.
    return $count == 1 ? $values[0] : $values;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FeedImportConfigurable::$options protected property
FeedImportConfigurable::cleanLines public static function Helper function to get lines of a string
FeedImportConfigurable::setOptions public function Sets options for this instance 4
FeedImportReader::$items protected property
FeedImportReader::formatPath public function Override this to preprocess your paths before they are used in map(). 2
FeedImportReader::get abstract public function This method returns the next available item or NULL if there are no items left. 6
FeedImportReader::getStreamContext public function Returns a stream context
FeedImportReader::init abstract public function Here you'll init your reader. 6
FeedImportReader::__construct final public function Constructor of reader. Constructor is final but you'll have to implement init() to init your reader.
FeedImportReader::__destruct public function Destructor. 2
FeedImportSimpleXPathReader::map public function Returns a value mapped from obj by path. Overrides FeedImportReader::map