class ServerFileList in Filebrowser 3.x
Same name and namespace in other branches
- 8.2 src/ServerFileList.php \Drupal\filebrowser\ServerFileList
Hierarchy
- class \Drupal\filebrowser\ServerFileList
Expanded class hierarchy of ServerFileList
1 file declares its use of ServerFileList
- DisplayFileList.php in src/
File/ DisplayFileList.php
File
- src/
ServerFileList.php, line 8
Namespace
Drupal\filebrowserView source
class ServerFileList {
/**
* @var array
*/
protected $serverFileList;
/**
* @var NodeInterface
*/
protected $node;
/**
* @var $string
*/
protected $relativePath;
/**
* @var Common
*/
protected $common;
/**
* @var Filebrowser
*/
protected $filebrowser;
/**
* ServerFileList constructor.
* @param \Drupal\node\NodeInterface $node
* @param string $relative_path
*/
public function __construct(NodeInterface $node, $relative_path) {
$this->serverFileList = $this
->createServerFileList($node, $relative_path);
$this->common = \Drupal::service('filebrowser.common');
$this->filebrowser = $node->filebrowser;
}
public function getList() {
return $this->serverFileList;
}
/**
* Retrieves files from the file system
* @param NodeInterface $node
* @param string $relative_path
* @return array list of files filtered as per node settings and restrictions
* returns an array of objects keyed to the uri:
* [public://directory/ic_autorenew_white_18px.svg] => stdClass Object(
* [uri] => public://directory/ic_autorenew_white_18px.svg // file_scan_directory
* [filename] => ic_autorenew_white_18px.svg // file_scan_directory
* [name] => ic_autorenew_white_18px // file_scan_directory
* [url] => http://drupal8.dev/sites/default/files/NFTR/file.svg
* [mimetype] => application/octet-stream
* [size] => 394
* [type] => file
* [timestamp] => 1460968364)
*/
protected function createServerFileList($node, $relative_path) {
/** @var Filebrowser $folder_path */
$folder_path = $node->filebrowser->folderPath;
$directory = $folder_path . $relative_path;
$files = \Drupal::service('file_system')
->scanDirectory($directory, '/.*/', [
'recurse' => false,
]);
$validator = \Drupal::service('filebrowser.validator');
$guessor = \Drupal::service('file.mime_type.guesser');
foreach ($files as $key => $file) {
$file->url = file_create_url($file->uri);
// Complete the required file data
$file->mimetype = $guessor
->guess($file->filename);
$file->size = filesize($file->uri);
$file->type = filetype($file->uri);
$file->timestamp = filectime($file->uri);
if ($file->type != 'dir' && !$validator
->whiteListed($file->filename, $node->filebrowser->whitelist) || $validator
->blackListed($file->filename, $node->filebrowser->forbiddenFiles) || !$node->filebrowser->exploreSubdirs && $file->type == 'dir') {
unset($files[$key]);
}
}
return $files;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ServerFileList:: |
protected | property | ||
ServerFileList:: |
protected | property | ||
ServerFileList:: |
protected | property | ||
ServerFileList:: |
protected | property | ||
ServerFileList:: |
protected | property | ||
ServerFileList:: |
protected | function | Retrieves files from the file system | |
ServerFileList:: |
public | function | ||
ServerFileList:: |
public | function | ServerFileList constructor. |