class DrupalTempFileAdapter in Backup and Migrate 8.4
Class DrupalTempFileAdapter.
@package BackupMigrate\Drupal\File
Hierarchy
- class \BackupMigrate\Core\File\TempFileAdapter implements TempFileAdapterInterface
- class \BackupMigrate\Drupal\File\DrupalTempFileAdapter implements TempFileAdapterInterface
Expanded class hierarchy of DrupalTempFileAdapter
File
- src/
File/ DrupalTempFileAdapter.php, line 14
Namespace
BackupMigrate\Drupal\FileView source
class DrupalTempFileAdapter extends TempFileAdapter implements TempFileAdapterInterface {
/**
* The Drupal file system for provisioning temp files.
*
* @var \Drupal\Core\File\FileSystemInterface
*/
protected $filesystem;
/**
* Construct a manager.
*
* @param \Drupal\Core\File\FileSystem $filesystem
* A file path or stream URL for the temp directory.
* @param string $dir
* The directory to save to.
* @param string $prefix
* A string prefix to add to each created file.
*/
public function __construct(FileSystemInterface $filesystem, $dir = 'temporary://', $prefix = 'bam') {
// Set the prefix and initialize the temp file tracking.
parent::__construct($dir, $prefix);
$this->filesystem = $filesystem;
}
/**
* {@inheritdoc}
*/
public function createTempFile($ext = '') {
// Add a dot to the file extension.
$ext = $ext ? '.' . $ext : '';
$file = $this->filesystem
->tempnam($this->dir, $this->prefix);
if (!$file) {
throw new \Exception('Could not create a temporary file to write to.');
}
$this->tempfiles[] = $file;
return $file;
}
/**
* {@inheritdoc}
*/
public function deleteTempFile($filename) {
// Only delete files that were created by this manager.
if (in_array($filename, $this->tempfiles)) {
if (file_exists($filename)) {
if (!$this->filesystem
->unlink($filename)) {
throw new \Exception('Could not delete a temporary file.');
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalTempFileAdapter:: |
protected | property | The Drupal file system for provisioning temp files. | |
DrupalTempFileAdapter:: |
public | function |
Get a temporary file that can be written to. Overrides TempFileAdapter:: |
|
DrupalTempFileAdapter:: |
public | function |
Delete a temporary file. Overrides TempFileAdapter:: |
|
DrupalTempFileAdapter:: |
public | function |
Construct a manager. Overrides TempFileAdapter:: |
|
TempFileAdapter:: |
protected | property | The path to the temp directory. | |
TempFileAdapter:: |
protected | property | A prefix to add to all temp files. | |
TempFileAdapter:: |
protected | property | The list of files created by this manager. | |
TempFileAdapter:: |
public | function |
Delete all temp files which have been created. Overrides TempFileAdapterInterface:: |
|
TempFileAdapter:: |
public | function | Destruct the manager. Delete all the temporary files when this manager is destroyed. |