Version 3.0
New technologies
This commit is contained in:
46
api/common/Alias/File.php
Normal file
46
api/common/Alias/File.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace Common\Alias;
|
||||
|
||||
use function Safe\{fopen,fclose,fwrite};
|
||||
use Common\Concept\File as FileInterface;
|
||||
|
||||
abstract class File implements FileInterface
|
||||
{
|
||||
protected string $filename;
|
||||
public function setFilename(string $filename): FileInterface
|
||||
{
|
||||
$this->filename = $filename;
|
||||
return $this;
|
||||
}
|
||||
public function getFilename(): string
|
||||
{
|
||||
return $this->filename;
|
||||
}
|
||||
|
||||
public function isDir(): bool
|
||||
{
|
||||
return is_dir($this->getFilename());
|
||||
}
|
||||
public function isReadable(): bool
|
||||
{
|
||||
return is_readable($this->getFilename());
|
||||
}
|
||||
public function isWriteable(): bool
|
||||
{
|
||||
return is_writeable($this->getFilename());
|
||||
}
|
||||
|
||||
public function read(?int $length = null): string
|
||||
{
|
||||
$fh = fopen($this->getFilename(), 'r');
|
||||
$str = fgets($fh, $length);
|
||||
fclose($fh);
|
||||
return $str;
|
||||
}
|
||||
public function write(string $data, ?int $length = null): void
|
||||
{
|
||||
$fh = fopen($this->getFilename(), 'r');
|
||||
fwrite($fh, $data, $length);
|
||||
fclose($fh);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user