You are here

class RawFetcherResult in Feeds 8.3

A fetcher result object that accepts a raw string.

This will write the string to a file on-demand if the parser requests it.

Hierarchy

Expanded class hierarchy of RawFetcherResult

5 files declare their use of RawFetcherResult
FeedImportHandler.php in src/FeedImportHandler.php
OpmlParserTest.php in tests/src/Unit/Feeds/Parser/OpmlParserTest.php
RawFetcherResultTest.php in tests/src/Unit/Result/RawFetcherResultTest.php
SitemapParserTest.php in tests/src/Unit/Feeds/Parser/SitemapParserTest.php
SyndicationParserTest.php in tests/src/Unit/Feeds/Parser/SyndicationParserTest.php

File

src/Result/RawFetcherResult.php, line 13

Namespace

Drupal\feeds\Result
View source
class RawFetcherResult extends FetcherResult {
  use DependencySerializationTrait;

  /**
   * The raw input string.
   *
   * @var string
   */
  protected $raw;

  /**
   * The file system service.
   *
   * @var \Drupal\Core\File\FileSystemInterface
   */
  protected $fileSystem;

  /**
   * Constructs a RawFetcherResult object.
   *
   * @param string $raw
   *   The raw result string.
   * @param \Drupal\Core\File\FileSystemInterface $file_system
   *   (optional) The file system service.
   */
  public function __construct($raw, FileSystemInterface $file_system = NULL) {
    $this->raw = $raw;
    if (is_null($file_system)) {
      $file_system = \Drupal::service('file_system');
    }
    $this->fileSystem = $file_system;
  }

  /**
   * {@inheritdoc}
   */
  public function getRaw() {
    return $this
      ->sanitizeRaw($this->raw);
  }

  /**
   * {@inheritdoc}
   */
  public function getFilePath() {

    // Write to a temporary file if the parser expects a file.
    if ($this->filePath) {
      return $this->filePath;
    }
    $this->filePath = $this->fileSystem
      ->tempnam('temporary://', 'feeds-raw');
    file_put_contents($this->filePath, $this
      ->getRaw());
    return $this->filePath;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FetcherResult::$filePath protected property The filepath of the fetched item.
FetcherResult::checkFile protected function Checks that a file exists and is readable.
FetcherResult::sanitizeFile protected function Sanitizes the file in place.
FetcherResult::sanitizeRaw protected function Sanitizes the raw content string.
RawFetcherResult::$fileSystem protected property The file system service.
RawFetcherResult::$raw protected property The raw input string.
RawFetcherResult::getFilePath public function Returns the path to the file containing the file provided by the fetcher. Overrides FetcherResult::getFilePath
RawFetcherResult::getRaw public function Returns the file provided by the fetcher as a string. Overrides FetcherResult::getRaw
RawFetcherResult::__construct public function Constructs a RawFetcherResult object. Overrides FetcherResult::__construct