You are here

abstract class FeedImportUniVectorReader in Feed Import 8

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

Hierarchy

Expanded class hierarchy of FeedImportUniVectorReader

File

feed_import_base/src/FeedImportUniVectorReader.php, line 8

Namespace

Drupal\feed_import_base
View source
abstract class FeedImportUniVectorReader extends FeedImportReader {

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

  /**
   * {@inheritdoc}
   */
  public function formatPath($path) {
    return preg_split('/(\\s?\\|\\s?)/', $path, -1, PREG_SPLIT_NO_EMPTY);
  }

}

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::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
FeedImportUniVectorReader::formatPath public function Override this to preprocess your paths before they are used in map(). Overrides FeedImportReader::formatPath 1
FeedImportUniVectorReader::map public function Returns a value mapped from obj by path. Overrides FeedImportReader::map