You are here

class FeedsExJsonPathLines in Feeds extensible parsers 7

Same name and namespace in other branches
  1. 7.2 src/FeedsExJsonPathLines.inc \FeedsExJsonPathLines

Parses the JSON Lines format via JSONPath.

Hierarchy

Expanded class hierarchy of FeedsExJsonPathLines

3 string references to 'FeedsExJsonPathLines'
FeedsExJsonPathLines.test in src/Tests/FeedsExJsonPathLines.test
feeds_ex_feeds_plugins in ./feeds_ex.feeds.inc
Implements hook_feeds_plugins().
feeds_ex_update_7102 in ./feeds_ex.install
Checks if for any importers libraries got missing.

File

src/FeedsExJsonPathLines.inc, line 11
Contains FeedsExJsonPathLines.

View source
class FeedsExJsonPathLines extends FeedsExJsonPath {

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

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

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

  /**
   * {@inheritdoc}
   */
  protected function parseItems(FeedsSource $source, FeedsFetcherResult $fetcher_result, FeedsParserResult $result) {
    $expressions = $this
      ->prepareExpressions();
    $variable_map = $this
      ->prepareVariables($expressions);
    foreach ($this->iterator as $row) {
      $row = $this
        ->getEncoder()
        ->convertEncoding($row);
      try {
        $row = FeedsExJsonUtility::decodeJsonArray($row);
      } catch (RuntimeException $e) {

        // An array wasn't returned. Skip this item.
        continue;
      }
      if ($item = $this
        ->executeSources($row, $expressions, $variable_map)) {
        $result->items[] = $item;
      }
    }
  }

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

  /**
   * {@inheritdoc}
   */
  protected function executeSourceExpression($machine_name, $expression, $row) {
    $result = $this
      ->getParser()
      ->search($row, $expression);
    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::$encoder protected property The encoder used to convert encodings.
FeedsExBase::$encoderClass protected property The class used as the text encoder. 1
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 1
FeedsExBase::debug protected function Renders our debug messages into a list.
FeedsExBase::executeSources protected function Executes the source expressions.
FeedsExBase::getEncoder public function Returns the encoder.
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::prepareRaw protected function Prepares the raw string for parsing.
FeedsExBase::prepareVariables protected function Prepares the variable map used to substitution.
FeedsExBase::printErrors protected function Prints errors to the screen.
FeedsExBase::setEncoder public function Sets the encoder.
FeedsExBase::setMessenger public function Sets the messenger to be used to display messages.
FeedsExBase::sourceDefaults public function
FeedsExBase::sourceForm public function
FeedsExBase::sourceFormValidate public function
FeedsExBase::sourceSave public function
FeedsExBase::stopErrorHandling protected function Stops internal error handling. 1
FeedsExJsonPath::$parser protected property The JSONPath parser implementation.
FeedsExJsonPath::executeContext protected function Returns rows to be parsed. Overrides FeedsExBase::executeContext
FeedsExJsonPath::getErrors protected function Returns the errors after parsing. Overrides FeedsExBase::getErrors
FeedsExJsonPath::getParser protected function Returns the JSONPath parser.
FeedsExJsonPath::loadLibrary protected function Loads the necessary library. Overrides FeedsExBase::loadLibrary
FeedsExJsonPath::startErrorHandling protected function Starts internal error handling. Overrides FeedsExBase::startErrorHandling
FeedsExJsonPath::validateExpression protected function Validates an expression. Overrides FeedsExBase::validateExpression
FeedsExJsonPathLines::$iterator protected property The file iterator.
FeedsExJsonPathLines::cleanUp protected function Allows subclasses to cleanup after parsing. Overrides FeedsExJsonPath::cleanUp
FeedsExJsonPathLines::executeSourceExpression protected function Executes a single source expression. Overrides FeedsExJsonPath::executeSourceExpression
FeedsExJsonPathLines::hasConfigurableContext protected function Returns whether or not this parser uses a context query. Overrides FeedsExBase::hasConfigurableContext
FeedsExJsonPathLines::parseItems protected function Performs the actual parsing. Overrides FeedsExBase::parseItems
FeedsExJsonPathLines::setUp protected function Allows subclasses to prepare for parsing. Overrides FeedsExBase::setUp