class DrupalTempFileAdapter in Backup and Migrate 5.0.x
@package Drupal\backup_migrate\Drupal\File
Hierarchy
- class \Drupal\backup_migrate\Core\File\TempFileAdapter implements TempFileAdapterInterface
- class \Drupal\backup_migrate\Drupal\File\DrupalTempFileAdapter implements TempFileAdapterInterface
Expanded class hierarchy of DrupalTempFileAdapter
2 files declare their use of DrupalTempFileAdapter
- backup_migrate.module in ./
backup_migrate.module - Primary hook implementations for Backup Migrate.
- MySQLiSource.php in src/
Core/ Source/ MySQLiSource.php
File
- src/
Drupal/ File/ DrupalTempFileAdapter.php, line 14
Namespace
Drupal\backup_migrate\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. |