You are here

class FeedsExJmesPathLines in Feeds extensible parsers 7.2

Same name and namespace in other branches
  1. 7 src/FeedsExJmesPathLines.inc \FeedsExJmesPathLines

Parses JSON Lines documents with JMESPath.

Hierarchy

Expanded class hierarchy of FeedsExJmesPathLines

2 string references to 'FeedsExJmesPathLines'
FeedsExJmesPathLinesUnitTests::setUp in src/Tests/FeedsExJmesPathLines.test
feeds_ex_feeds_plugins in ./feeds_ex.feeds.inc
Implements hook_feeds_plugins().

File

src/FeedsExJmesPathLines.inc, line 11
Contains FeedsExJmesPathLines.

View source
class FeedsExJmesPathLines extends FeedsExJmesPath {

  /**
   * The file iterator.
   *
   * @var FeedsExLineIterator
   */
  protected $iterator;

  /**
   * {@inheritdoc}
   */
  protected function executeContext(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
    return $this->iterator;
  }

  /**
   * {@inheritdoc}
   */
  protected function hasConfigurableContext() {
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  protected function setUp(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
    parent::setUp($source, $fetcher_result);
    $this->iterator = new FeedsExLineIterator($fetcher_result
      ->getFilePath());
    $this->iterator
      ->setLineLimit($source->importer
      ->getLimit());
    $state = $source
      ->state(FEEDS_PARSE);
    if (!$state->total) {
      $state->total = $this->iterator
        ->getSize();
    }
    $state->start = $state->pointer ? $state->pointer : 0;
    $this->iterator
      ->setStartPosition($state->start);
  }

  /**
   * {@inheritdoc}
   */
  protected function cleanUp(FeedsSource $source, FeedsParserResult $result) {
    parent::cleanUp($source, $result);
    $state = $source
      ->state(FEEDS_PARSE);
    $state->pointer = $this->iterator
      ->ftell();
    unset($this->iterator);
  }

  /**
   * {@inheritdoc}
   */
  protected function executeSourceExpression($machine_name, $expression, $row) {

    // Row is a JSON string.
    if ($encoding = $this
      ->detectEncoding($row)) {
      $row = $this
        ->convertEncoding($row, $encoding);
    }
    $row = drupal_json_decode($row);
    $result = $this->jmesPath
      ->search($expression, $row);
    if (is_scalar($result)) {
      return $result;
    }

    // Return a single value if there's only one value.
    return count($result) === 1 ? reset($result) : $result;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FeedsExBase::$isMultibyte protected property Whether the current system handles mb_* functions.
FeedsExBase::$messenger protected property The object used to display messages to the user.
FeedsExBase::configDefaults public function 1
FeedsExBase::configForm public function 1
FeedsExBase::configFormTableColumn protected function Returns a form element for a specific column. 1
FeedsExBase::configFormTableHeader protected function Reuturns the list of table headers. 1
FeedsExBase::configFormValidate public function
FeedsExBase::convertEncoding protected function Converts a string to UTF-8. 1
FeedsExBase::debug protected function Renders our debug messages into a list.
FeedsExBase::delegateParsing protected function Delegates parsing to the subclass.
FeedsExBase::detectEncoding protected function Detects the encoding of a string.
FeedsExBase::executeSources protected function Executes the source expressions.
FeedsExBase::getFormHeader protected function Returns the configuration form table header.
FeedsExBase::getMappingSources public function
FeedsExBase::getMessenger public function Returns the messenger.
FeedsExBase::hasConfigForm public function
FeedsExBase::hasSourceConfig public function
FeedsExBase::logErrors protected function Logs errors.
FeedsExBase::parse public function
FeedsExBase::prepareExpressions protected function Prepares the expressions for parsing.
FeedsExBase::prepareVariables protected function Prepares the variable map used to substitution.
FeedsExBase::printErrors protected function Prints errors to the screen.
FeedsExBase::setMessenger public function Sets the messenger to be used to display messages.
FeedsExBase::setMultibyte public function Sets the multibyte handling.
FeedsExBase::sourceDefaults public function
FeedsExBase::sourceForm public function
FeedsExBase::sourceFormValidate public function
FeedsExBase::sourceSave public function
FeedsExBase::startErrorHandling protected function Starts internal error handling. 1
FeedsExBase::stopErrorHandling protected function Stops internal error handling. 1
FeedsExBase::__construct protected function 1
FeedsExJmesPath::$jmesPath protected property The JMESPath parser.
FeedsExJmesPath::getErrors protected function Returns the errors after parsing. Overrides FeedsExBase::getErrors
FeedsExJmesPath::loadLibrary protected function Loads the necessary library. Overrides FeedsExBase::loadLibrary
FeedsExJmesPath::validateExpression protected function Validates an expression. Overrides FeedsExBase::validateExpression
FeedsExJmesPathLines::$iterator protected property The file iterator.
FeedsExJmesPathLines::cleanUp protected function Allows subclasses to cleanup after parsing. Overrides FeedsExJmesPath::cleanUp
FeedsExJmesPathLines::executeContext protected function Returns rows to be parsed. Overrides FeedsExJmesPath::executeContext
FeedsExJmesPathLines::executeSourceExpression protected function Executes a single source expression. Overrides FeedsExJmesPath::executeSourceExpression
FeedsExJmesPathLines::hasConfigurableContext protected function Returns whether or not this parser uses a context query. Overrides FeedsExBase::hasConfigurableContext
FeedsExJmesPathLines::setUp protected function Allows subclasses to prepare for parsing. Overrides FeedsExJmesPath::setUp