public function Importer::scan in Default Content Deploy 8
Returns a list of file objects.
Parameters
string $directory: Absolute path to the directory to search.
Return value
object[] List of stdClass objects with name and uri properties.
1 call to Importer::scan()
- Importer::prepareForImport in src/
Importer.php - Import data from JSON and create new entities, or update existing.
File
- src/
Importer.php, line 251
Class
- Importer
- A service for handling import of default content.
Namespace
Drupal\default_content_deployCode
public function scan($directory) {
// Use Unix paths regardless of platform, skip dot directories, follow
// symlinks (to allow extensions to be linked from elsewhere), and return
// the RecursiveDirectoryIterator instance to have access to getSubPath(),
// since SplFileInfo does not support relative paths.
$flags = \FilesystemIterator::UNIX_PATHS;
$flags |= \FilesystemIterator::SKIP_DOTS;
$flags |= \FilesystemIterator::CURRENT_AS_SELF;
$directory_iterator = new \RecursiveDirectoryIterator($directory, $flags);
$iterator = new \RecursiveIteratorIterator($directory_iterator);
$files = [];
/* @var \SplFileInfo $file_info */
foreach ($iterator as $file_info) {
// Skip directories and non-json files.
if ($file_info
->isDir() || $file_info
->getExtension() != 'json') {
continue;
}
$file = new \stdClass();
$file->name = $file_info
->getFilename();
$file->uri = $file_info
->getPathname();
$files[$file->uri] = $file;
}
return $files;
}