Spatie\Backup\Tasks\Backup\TemporaryDirectory::create PHP Method

create() public static method

public static create ( string $path = '' ) : TemporaryDirectory
$path string
return TemporaryDirectory
    public static function create(string $path = '') : TemporaryDirectory
    {
        $filesystem = new Filesystem();
        return (new static($filesystem))->setPath($path . '/' . Carbon::now()->format('Y-m-d-H-i-s'));
    }

Usage Example

Example #1
0
 public function run()
 {
     $this->temporaryDirectory = TemporaryDirectory::create();
     try {
         if (!count($this->backupDestinations)) {
             throw InvalidBackupJob::noDestinationsSpecified();
         }
         $manifest = $this->createBackupManifest();
         if (!$manifest->count()) {
             throw InvalidBackupJob::noFilesToBeBackedUp();
         }
         $zipFile = $this->createZipContainingEveryFileInManifest($manifest);
         $this->copyToBackupDestinations($zipFile);
     } catch (Exception $exception) {
         consoleOutput()->error("Backup failed because {$exception->getMessage()}." . PHP_EOL . $exception->getTraceAsString());
         event(new BackupHasFailed($exception));
     }
     $this->temporaryDirectory->delete();
 }