clrghouz/app/Classes/File/Item.php

69 lines
1.5 KiB
PHP
Raw Normal View History

2021-04-01 10:59:15 +00:00
<?php
namespace App\Classes\File;
use Illuminate\Support\Facades\Storage;
2021-04-01 10:59:15 +00:00
use App\Models\Address;
2021-04-01 10:59:15 +00:00
final class Item extends Receive
{
private const LOCATION = 'local';
2021-04-01 10:59:15 +00:00
/** @var Address The address that sent us this item */
private Address $ao;
private string $recvas;
private int $recvmtime;
private int $recvsize;
2021-04-01 10:59:15 +00:00
/**
* @throws \Exception
2021-04-01 10:59:15 +00:00
*/
public function __construct(Address $ao,string $recvas,int $mtime,int $size)
2021-04-01 10:59:15 +00:00
{
parent::__construct();
$this->ao = $ao;
$this->recvas = $recvas;
$this->recvmtime = $mtime;
$this->recvsize = $size;
$this->ftype = self::IS_FILE;
}
public function __get($key) {
switch ($key) {
case 'exists':
return Storage::disk(self::LOCATION)->exists($this->rel_name);
case 'rel_name':
return sprintf('%s/%04X-%s',config('app.fido'),$this->ao->id,$this->recvas);
case 'full_name':
return Storage::disk(self::LOCATION)->path($this->rel_name);
case 'match_mtime':
return $this->mtime === $this->recvmtime;
case 'match_size':
return $this->size === $this->recvsize;
2021-04-01 10:59:15 +00:00
case 'nameas':
return $this->recvas;
case 'recvmtime':
return $this->recvmtime;
case 'recvsize':
return $this->recvsize;
2021-04-01 10:59:15 +00:00
case 'name_size_time':
return sprintf('%s %lu %lu',$this->recvas,$this->recvsize,$this->recvmtime);
2021-04-01 10:59:15 +00:00
case 'mtime':
return Storage::disk(self::LOCATION)->lastModified($this->rel_name);
case 'size':
return Storage::disk(self::LOCATION)->size($this->rel_name);
2021-04-01 10:59:15 +00:00
default:
return parent::__get($key);
2021-04-01 10:59:15 +00:00
}
}
}