create filesystem abstraction
This commit is contained in:
parent
be2c51bfb7
commit
d59d444952
14 changed files with 44 additions and 64 deletions
|
|
@ -2,11 +2,13 @@
|
|||
|
||||
namespace App\Shared\Files;
|
||||
|
||||
interface FileUploader
|
||||
interface Filesystem
|
||||
{
|
||||
public function upload(FileToUpload $file, string $folder): string;
|
||||
|
||||
public function url(string $path): string;
|
||||
|
||||
public function delete(string $path): void;
|
||||
|
||||
public function read(string $path): ?string;
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ namespace App\Shared\Files;
|
|||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class LaravelFileUploader implements FileUploader
|
||||
class LaravelFilesystem implements Filesystem
|
||||
{
|
||||
public function upload(FileToUpload $file, string $folder): string
|
||||
{
|
||||
|
|
@ -25,6 +25,15 @@ class LaravelFileUploader implements FileUploader
|
|||
Storage::disk('public')->delete($path);
|
||||
}
|
||||
|
||||
public function read(string $path): ?string
|
||||
{
|
||||
if (!Storage::disk('public')->exists($path)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Storage::disk('public')->get($path);
|
||||
}
|
||||
|
||||
private function extensionFor(FileToUpload $file): string
|
||||
{
|
||||
$mimeExtensions = [
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Shared\Files;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class LaravelStoredFileReader implements StoredFileReader
|
||||
{
|
||||
public function read(string $path): ?string
|
||||
{
|
||||
if (!Storage::disk('public')->exists($path)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Storage::disk('public')->get($path);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Shared\Files;
|
||||
|
||||
interface StoredFileReader
|
||||
{
|
||||
public function read(string $path): ?string;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue