Started to implement a very basic builtin footprints gallery tool

This commit is contained in:
Jan Böhmer 2023-01-09 22:51:12 +01:00
parent 39d4f06c12
commit ddd8a66024
3 changed files with 96 additions and 0 deletions

View file

@ -42,6 +42,39 @@ class BuiltinAttachmentsFinder
$this->cache = $cache;
}
/**
* Returns an array with all builtin footprints, grouped by their folders
* The array have the form of: [
* '/path/to/folder' => [
* '%FOOTPRINTS%/path/to/folder/file1.png',
* '%FOOTPRINTS%/path/to/folder/file2.png',
* ]
* @return array
*/
public function getListOfFootprintsGroupedByFolder(): array
{
$finder = new Finder();
//We search only files
$finder->files();
$finder->in($this->pathResolver->getFootprintsPath());
$output = [];
foreach($finder as $file) {
$folder = $file->getRelativePath();
//Normalize path (replace \ with /)
$folder = str_replace('\\', '/', $folder);
if(!isset($output[$folder])) {
$output[$folder] = [];
}
//Add file to group
$output[$folder][] = $this->pathResolver->realPathToPlaceholder($file->getPathname());
}
return $output;
}
/**
* Returns a list of all builtin ressources.
* The array is a list of the relative filenames using the %PLACEHOLDERS%.