kuvia/app/Entity/File.php

50 lines
1.2 KiB
PHP

<?php
namespace App\Entity;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
class File
{
private $drive;
private $path;
private $size = null;
private $content = null;
public function __construct(?string $drive, ?string $path)
{
Log::info("Create File Object", ["path" => $path, "driver" => $drive]);
$this->drive = $drive;
$this->path = $path;
}
public function setContent($content) {
$this->content = $content;
}
public function getSize() {
if(is_null($this->size)) {
$this->size = Storage::disk($this->drive)->size($this->path);
}
return $this->size;
}
public function getContent() {
if(is_null($this->content)) {
Log::info("Get Content for file from Storage", ["driver" => $this->drive, "path" => $this->path]);
$this->content = Storage::disk($this->drive)->get($this->path);
}
return $this->content;
}
public function response() {
return Storage::disk($this->drive)->response($this->path);
}
public function getDrive() {
return $this->drive;
}
}