mirror of
https://github.com/bitinflow/bunny-cli.git
synced 2026-03-13 13:45:54 +00:00
Improve caching, performance and add dry-run
This commit is contained in:
@@ -4,15 +4,17 @@ namespace App\Bunny\Filesystem;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class LocalFile implements File
|
||||
class LocalFile implements File, FileStreamable, FileSerialized
|
||||
{
|
||||
private string $filename;
|
||||
private ?string $checksum;
|
||||
private ?string $contents;
|
||||
|
||||
public function __construct(string $filename, ?string $checksum)
|
||||
public function __construct(string $filename, ?string $checksum, string $contents = null)
|
||||
{
|
||||
$this->filename = $filename;
|
||||
$this->checksum = $checksum;
|
||||
$this->contents = $contents;
|
||||
}
|
||||
|
||||
public function getFilename($search = '', $replace = ''): string
|
||||
@@ -20,13 +22,35 @@ class LocalFile implements File
|
||||
return Str::replaceFirst($search, $replace, $this->filename);
|
||||
}
|
||||
|
||||
public function getChecksum(): string
|
||||
public function getChecksum(): ?string
|
||||
{
|
||||
return $this->checksum;
|
||||
}
|
||||
|
||||
public function isDirectory(): bool
|
||||
{
|
||||
return $this->checksum == null;
|
||||
return $this->getChecksum() === null;
|
||||
}
|
||||
|
||||
public function getResource()
|
||||
{
|
||||
if ($this->contents) {
|
||||
return $this->contents;
|
||||
}
|
||||
|
||||
return fopen($this->getFilename(), 'r');
|
||||
}
|
||||
|
||||
public function toArray(string $search = '', string $replace = ''): array
|
||||
{
|
||||
return [
|
||||
'sha256' => $this->getChecksum(),
|
||||
'filename' => $this->getFilename($search, $replace),
|
||||
];
|
||||
}
|
||||
|
||||
public static function fromArray(array $array): self
|
||||
{
|
||||
return new self($array['filename'], $array['sha256']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user