Version 3.0
New technologies
This commit is contained in:
45
api/common/Alias/Filesystem.php
Normal file
45
api/common/Alias/Filesystem.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?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));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user