You are here

function ServiceAuditFilesNotInDatabase::_auditfiles_not_in_database_get_files in Audit Files 8

Retrieves a list of files in the given path.

Parameters

string $path: The path to search for files in.

Return value

array The list of files and diretories found in the given path.

1 call to ServiceAuditFilesNotInDatabase::_auditfiles_not_in_database_get_files()
ServiceAuditFilesNotInDatabase::_auditfiles_not_in_database_get_files_for_report in src/ServiceAuditFilesNotInDatabase.php
Get files for report.

File

src/ServiceAuditFilesNotInDatabase.php, line 144
providing the service that used in not in database functionality.

Class

ServiceAuditFilesNotInDatabase

Namespace

Drupal\auditfiles

Code

function _auditfiles_not_in_database_get_files($path) {
  $config = \Drupal::config('auditfiles_config.settings');
  $file_system_stream = $config
    ->get('auditfiles_file_system_path') ? $config
    ->get('auditfiles_file_system_path') : 'public';
  $real_files_path = drupal_realpath($file_system_stream . '://');
  $exclusions = $this
    ->_auditfiles_get_exclusions();

  // The variable to store the data being returned.
  $file_list = [];
  if (empty($path)) {
    $scan_path = $real_files_path;
  }
  else {
    $scan_path = $real_files_path . DIRECTORY_SEPARATOR . $path;
  }

  // Get the files in the specified directory.
  $files = scandir($scan_path);
  foreach ($files as $file) {
    if ($file != '.' && $file != '..') {

      // Check to see if this file should be included.
      $include_file = $this
        ->_auditfiles_not_in_database_include_file($real_files_path . DIRECTORY_SEPARATOR . $path, $file, $exclusions);
      if ($include_file) {

        // The file is to be included, so add it to the data array.
        $file_list[] = [
          'file_name' => $file,
          'path_from_files_root' => $path,
        ];
      }
    }
  }
  return $file_list;
}