You are here

public static function RealisticDummyContentEnvironment::getFileContents in Realistic Dummy Content 3.x

Same name and namespace in other branches
  1. 8.2 api/src/includes/RealisticDummyContentEnvironment.php \Drupal\realistic_dummy_content_api\includes\RealisticDummyContentEnvironment::getFileContents()
  2. 7.2 api/src/includes/RealisticDummyContentEnvironment.php \Drupal\realistic_dummy_content_api\includes\RealisticDummyContentEnvironment::getFileContents()

Returns the trimmed contents of a Drpual file object, or NULL if empty.

Parameters

object $file: A drupal file object.

Return value

null|string NULL if no contents in file, or if an error occurred; otherwise a string with the trimmed contents of the file.

File

api/src/includes/RealisticDummyContentEnvironment.php, line 424

Class

RealisticDummyContentEnvironment
The abstract base environment.

Namespace

Drupal\realistic_dummy_content_api\includes

Code

public static function getFileContents($file) {
  try {
    if (!is_object($file)) {
      throw new RealisticDummyContentException('Please use a file object');
    }
    return trim(self::get()
      ->fileGetContents($file->uri));
  } catch (\Throwable $e) {
    return NULL;
  }
}