dgd-backupper-php/app/Utils/Builder.php

89 lines
1.8 KiB
PHP

<?php
namespace App\Utils;
use \AdamBrett\ShellWrapper\Command\Builder as CommandBuilder;
use App\Exceptions\BackupFolderNotFoundException;
use App\Exceptions\CleanException;
use Throwable;
abstract class Builder
{
private $backupFolder;
private $containerName;
private $clean;
/**
* Builder constructor.
*/
public function __construct()
{
$this->clean = false;
}
public function __destruct()
{
try {
if ($this->clean) {
$files = glob($this->backupFolder . '/*');
foreach($files as $file){
is_file($file) ? unlink($file) : null;
}
}
} catch (\Exception $exception) {
throw new CleanException($exception->getMessage());
}
}
/**
* @param $backupFolder
* @return Builder
* @throws Throwable
*/
public function setBackupFolder($backupFolder): Builder
{
throw_if(!file_exists($backupFolder), new BackupFolderNotFoundException('Backup folder not exist!'));
$this->backupFolder = $backupFolder;
return $this;
}
/**
* @return string
*/
public function getBackupFolder(): string
{
return $this->backupFolder;
}
/**
* @param $containerName
* @return Builder
*/
public function setContainerName($containerName): Builder
{
$this->containerName = $containerName;
return $this;
}
/**
* @return string
*/
public function getContainerName(): string
{
return $this->containerName;
}
/**
* @param bool $clean
*/
public function setClean(bool $clean): void
{
$this->clean = $clean;
}
/**
* @return CommandBuilder
*/
abstract public function builder(): CommandBuilder;
}