You are here

static function Environment::SortCandidateFiles in Realistic Dummy Content 8

Given a list of candidate files, sort them by names and parts.

Parameters

$candidate_files: An array keyed by filename which contains drupal file objects, like this:

'one.txt' => [file object] 'two.txt.attribute.txt' => [file object] 'two.txt.attribute1.txt' => [file object] 'three.txt' => [file object]

$extensions = NULL: If set, only return file groups whose base file is in one of the extenstions. For example, given an extension jpg,png, and a file structure with

a.jpg a.jpg.alt.txt b.txt

This function will return:

a.jpg => file => [a.jpg] attributes => alt => [a.jpg.alt.txt]

Return value

A sorted array which looks like:

one.txt => array('file' => [file object]), two.txt = array( attributes => array( 'attribute' => [file object], 'attribute1' => [file object], ) ), three.txt => array('file' => [file object]),

Throws

Exception

2 calls to Environment::SortCandidateFiles()
Environment::GetAllFileGroups in api/src/environments/Environment.php
Returns all files with a given extension for a given filepath.
EnvironmentTest::testSortCandidateFiles in api/tests/src/Unit/environments/EnvironmentTest.php
Test that file names are properly parsed and combined.

File

api/src/environments/Environment.php, line 211
Define autoload class.

Class

Environment
The abstract base environment.

Namespace

Drupal\realistic_dummy_content_api\environments

Code

static function SortCandidateFiles($candidate_files, $extensions = NULL) {
  foreach ($candidate_files as $candidate_filename => $candidate_file) {
    if (!is_string($candidate_filename)) {
      throw new Exception('array keys should be strings');
    }
    if (!is_object($candidate_file)) {
      throw new Exception('array values should be file objects');
    }
    if (strpos($candidate_filename, '/') !== FALSE) {
      throw new Exception('Please do not pass file paths with slashes (/) to ' . __FUNCTION__);
    }
  }
  $return = self::SortCandidateFiles_($candidate_files, $extensions);
  return $return;
}