DrupalTempFileAdapter.php in Backup and Migrate 5.0.x
File
src/Drupal/File/DrupalTempFileAdapter.php
View source
<?php
namespace Drupal\backup_migrate\Drupal\File;
use Drupal\backup_migrate\Core\File\TempFileAdapter;
use Drupal\backup_migrate\Core\File\TempFileAdapterInterface;
use Drupal\Core\File\FileSystemInterface;
class DrupalTempFileAdapter extends TempFileAdapter implements TempFileAdapterInterface {
protected $filesystem;
public function __construct(FileSystemInterface $filesystem, $dir = 'temporary://', $prefix = 'bam') {
parent::__construct($dir, $prefix);
$this->filesystem = $filesystem;
}
public function createTempFile($ext = '') {
$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;
}
public function deleteTempFile($filename) {
if (in_array($filename, $this->tempfiles)) {
if (file_exists($filename)) {
if (!$this->filesystem
->unlink($filename)) {
throw new \Exception('Could not delete a temporary file.');
}
}
}
}
}