static function RealisticDummyContentEnvironment::SortCandidateFiles in Realistic Dummy Content 7
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
RealisticDummyContentException
2 calls to RealisticDummyContentEnvironment::SortCandidateFiles()
- RealisticDummyContentEnvironment::GetAllFileGroups in api/
includes/ RealisticDummyContentEnvironment.inc - Returns all files with a given extension for a given filepath.
- realistic_dummy_content_UnitTestCase::testFiles in api/
tests/ realistic_dummy_content_api.unit.test - Test that file names are properly parsed and combined.
File
- api/
includes/ RealisticDummyContentEnvironment.inc, line 205 - Define RealisticDummyContentLiveEnvironment autoload class.
Class
- RealisticDummyContentEnvironment
- The abstract base environment.
Code
static function SortCandidateFiles($candidate_files, $extensions = NULL) {
foreach ($candidate_files as $candidate_filename => $candidate_file) {
if (!is_string($candidate_filename)) {
// Explicitly load the Exception class, because during unit tests the
// registry is not present.
module_load_include('inc', 'realistic_dummy_content_api', 'includes/RealisticDummyContentException');
throw new RealisticDummyContentException('array keys should be strings');
}
if (!is_object($candidate_file)) {
// Explicitly load the Exception class, because during unit tests the
// registry is not present.
module_load_include('inc', 'realistic_dummy_content_api', 'includes/RealisticDummyContentException');
throw new RealisticDummyContentException('array values should be file objects');
}
if (strpos($candidate_filename, '/') !== FALSE) {
// Explicitly load the Exception class, because during unit tests the
// registry is not present.
module_load_include('inc', 'realistic_dummy_content_api', 'includes/RealisticDummyContentException');
throw new RealisticDummyContentException('Please do not pass file paths with slashes (/) to ' . __FUNCTION__);
}
}
$return = self::SortCandidateFiles_($candidate_files, $extensions);
return $return;
}