46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
|
namespace Common\Alias;
|
|
|
|
use function Safe\{touch,mkdir,unlink};
|
|
use Common\Concept\Filesystem as FilesystemInterface;
|
|
|
|
abstract class Filesystem implements FilesystemInterface
|
|
{
|
|
protected string $base_path;
|
|
public function setBasePath(string $path): FilesystemInterface
|
|
{
|
|
$this->base_path = $path;
|
|
return $this;
|
|
}
|
|
public function getBasePath(): string
|
|
{
|
|
return $this->base_path;
|
|
}
|
|
|
|
public function buildPath(string $relative_path): string
|
|
{
|
|
return implode(DIRECTORY_SEPARATOR, [
|
|
$this->getBasePath(),
|
|
$relative_path
|
|
]);
|
|
}
|
|
|
|
public function has(string $relative_path): bool
|
|
{
|
|
return file_exists($this->buildPath($relative_path));
|
|
}
|
|
|
|
public function mkdir(string $relative_path): void
|
|
{
|
|
mkdir($this->buildPath($relative_path));
|
|
}
|
|
public function create(string $relative_path): void
|
|
{
|
|
touch($this->buildPath($relative_path));
|
|
}
|
|
public function delete(string $relative_path): void
|
|
{
|
|
unlink($this->buildPath($relative_path));
|
|
}
|
|
}
|