mirror of
https://github.com/bitinflow/bunny-cli.git
synced 2026-03-13 21:55:54 +00:00
Improve caching, performance and add dry-run
This commit is contained in:
@@ -5,7 +5,7 @@ namespace App\Bunny\Filesystem;
|
||||
use Illuminate\Support\Str;
|
||||
use stdClass;
|
||||
|
||||
class EdgeFile implements File
|
||||
class EdgeFile implements File, FileSerialized
|
||||
{
|
||||
private stdClass $file;
|
||||
|
||||
@@ -14,6 +14,16 @@ class EdgeFile implements File
|
||||
$this->file = $file;
|
||||
}
|
||||
|
||||
public static function fromFilename(string $path, string $sha256 = null): self
|
||||
{
|
||||
return new self((object)[
|
||||
'Path' => Str::replaceLast($basename = basename($path), '', $path),
|
||||
'ObjectName' => $basename,
|
||||
'IsDirectory' => Str::endsWith($path, '/'),
|
||||
'Checksum' => $sha256,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getFilename($search = '', $replace = ''): string
|
||||
{
|
||||
return Str::replaceFirst($search, $replace, $this->file->Path . $this->file->ObjectName);
|
||||
@@ -21,11 +31,24 @@ class EdgeFile implements File
|
||||
|
||||
public function isDirectory(): bool
|
||||
{
|
||||
return $this->file->IsDirectory;
|
||||
return $this->getChecksum() === null;
|
||||
}
|
||||
|
||||
public function getChecksum(): string
|
||||
public function getChecksum(): ?string
|
||||
{
|
||||
return $this->file->Checksum;
|
||||
return $this->file->IsDirectory ? null : $this->file->Checksum;
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'sha256' => $this->getChecksum(),
|
||||
'filename' => $this->getFilename(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function fromArray(array $array): self
|
||||
{
|
||||
return self::fromFilename($array['filename'], $array['sha256']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user