class FlysystemS3FileSystem in Flysystem - S3 8
Same name and namespace in other branches
- 2.0.x src/File/FlysystemS3FileSystem.php \Drupal\flysystem_s3\File\FlysystemS3FileSystem
Decorates the Drupal FileSystem service to handle chmod() for S3.
Hierarchy
- class \Drupal\Core\File\FileSystem implements FileSystemInterface
- class \Drupal\flysystem_s3\File\FlysystemS3FileSystem
Expanded class hierarchy of FlysystemS3FileSystem
1 string reference to 'FlysystemS3FileSystem'
1 service uses FlysystemS3FileSystem
File
- src/
File/ FlysystemS3FileSystem.php, line 13
Namespace
Drupal\flysystem_s3\FileView source
class FlysystemS3FileSystem extends FileSystem {
/**
* FlysystemS3FileSystem constructor.
*
* @param \Drupal\Core\File\FileSystemInterface $file_system
* The file system being decorated.
* @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager
* The stream wrapper manager.
* @param \Drupal\Core\Site\Settings $settings
* The site settings.
* @param \Psr\Log\LoggerInterface $logger
* The file logger channel.
*/
public function __construct(StreamWrapperManagerInterface $stream_wrapper_manager, Settings $settings, LoggerInterface $logger) {
parent::__construct($stream_wrapper_manager, $settings, $logger);
}
/**
* {@inheritdoc}
*
* Extend chmod(), respecting S3's ACL setting.
*
* With Drupal's private files, chmod() is called by file_save_upload() to
* ensure the new file is readable by the file server, using the same file
* system permissions as the public file system. However, since private files
* are stored outside of the docroot, they are forced to go be accessed
* through Drupal's file permissions handling.
*
* With S3, \Twistor\FlysystemStreamWrapper::stream_metadata() automatically
* maps chmod() calls to basic S3 ACLs, which means that while a file can be
* initially uploaded as 'private', Drupal will immediately chmod it to
* public using the default file mask in settings.php.
*
* This method checks to see if we are using a private S3 scheme, and if so,
* ensures that group / other permissions are always unset, ensuring the
* stream wrapper preserves private permissions.
*
* @param string $uri
* A string containing a URI file, or directory path.
* @param int $mode
* Integer value for the permissions. Consult PHP chmod() documentation for
* more information.
*
* @return bool
* TRUE for success, FALSE in the event of an error.
*
* @see \Twistor\FlysystemStreamWrapper::stream_metadata
*/
public function chmod($uri, $mode = NULL) {
$scheme = parent::uriScheme($uri);
if ($this
->isPrivateS3Scheme($scheme)) {
is_dir($uri) ? $mode = 0700 : ($mode = 0600);
}
return parent::chmod($uri, $mode);
}
/**
* Return if a scheme is a private S3 scheme.
*
* @param string $scheme
* The scheme to check.
*
* @return bool
* TRUE if the scheme's S3 acl is set to 'private'.
*/
protected function isPrivateS3Scheme($scheme) {
$settings = $this->settings
->get('flysystem', []);
return isset($settings[$scheme]) && $settings[$scheme]['driver'] == 's3' && isset($settings[$scheme]['config']['options']['ACL']) && $settings[$scheme]['config']['options']['ACL'] == 'private';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FileSystem:: |
protected | property | The file logger channel. | |
FileSystem:: |
protected | property | The site settings. | |
FileSystem:: |
protected | property | The stream wrapper manager. | |
FileSystem:: |
public | function |
Gets the filename from a given path. Overrides FileSystemInterface:: |
|
FileSystem:: |
constant | Default mode for new directories. See self::chmod(). | ||
FileSystem:: |
constant | Default mode for new files. See self::chmod(). | ||
FileSystem:: |
public | function |
Copies a file to a new location without invoking the file API. Overrides FileSystemInterface:: |
|
FileSystem:: |
public | function |
Creates a full file path from a directory and filename. Overrides FileSystemInterface:: |
|
FileSystem:: |
public | function |
Deletes a file without database changes or hook invocations. Overrides FileSystemInterface:: |
|
FileSystem:: |
public | function |
Deletes all files and directories in the specified filepath recursively. Overrides FileSystemInterface:: |
|
FileSystem:: |
public | function |
Gets the name of the directory from a given path. Overrides FileSystemInterface:: |
|
FileSystem:: |
protected | function | Internal function to handle directory scanning with recursion. | |
FileSystem:: |
public | function |
Determines the destination path for a file. Overrides FileSystemInterface:: |
|
FileSystem:: |
public | function |
Gets the path of the configured temporary directory. Overrides FileSystemInterface:: |
|
FileSystem:: |
public | function |
Creates a directory, optionally creating missing components in the path to
the directory. Overrides FileSystemInterface:: |
|
FileSystem:: |
protected | function | Helper function. Ensures we don't pass a NULL as a context resource to mkdir(). | |
FileSystem:: |
public | function |
Moves a file to a new location without database changes or hook invocation. Overrides FileSystemInterface:: |
|
FileSystem:: |
public | function |
Moves an uploaded file to a new location. Overrides FileSystemInterface:: |
|
FileSystem:: |
protected | function | Prepares the destination for a file copy or move operation. | |
FileSystem:: |
public | function |
Checks that the directory exists and is writable. Overrides FileSystemInterface:: |
|
FileSystem:: |
public | function |
Resolves the absolute filepath of a local URI or filepath. Overrides FileSystemInterface:: |
|
FileSystem:: |
public | function |
Removes a directory. Overrides FileSystemInterface:: |
|
FileSystem:: |
public | function |
Saves a file to the specified destination without invoking file API. Overrides FileSystemInterface:: |
|
FileSystem:: |
public | function |
Finds all files that match a given mask in a given directory. Overrides FileSystemInterface:: |
|
FileSystem:: |
public | function |
Creates a file with a unique filename in the specified directory. Overrides FileSystemInterface:: |
|
FileSystem:: |
public | function |
Deletes a file. Overrides FileSystemInterface:: |
|
FileSystem:: |
public | function |
Returns the scheme of a URI (e.g. a stream). Overrides FileSystemInterface:: |
|
FileSystem:: |
public | function |
Checks that the scheme of a stream URI is valid. Overrides FileSystemInterface:: |
|
FileSystemInterface:: |
constant | Flag used by ::prepareDirectory() -- create directory if not present. | ||
FileSystemInterface:: |
constant | Flag for dealing with existing files: Do nothing and return FALSE. | ||
FileSystemInterface:: |
constant | Flag for dealing with existing files: Appends number until name is unique. | ||
FileSystemInterface:: |
constant | Flag for dealing with existing files: Replace the existing file. | ||
FileSystemInterface:: |
constant | Flag used by ::prepareDirectory() -- file permissions may be changed. | ||
FlysystemS3FileSystem:: |
public | function |
Extend chmod(), respecting S3's ACL setting. Overrides FileSystem:: |
|
FlysystemS3FileSystem:: |
protected | function | Return if a scheme is a private S3 scheme. | |
FlysystemS3FileSystem:: |
public | function |
FlysystemS3FileSystem constructor. Overrides FileSystem:: |