25 lines
615 B
PHP
25 lines
615 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\Study;
|
|
use Illuminate\Support\Str;
|
|
|
|
final readonly class ReportStorage
|
|
{
|
|
public static function studyFolder(Study|int $study): string
|
|
{
|
|
$hash = md5($study instanceof Study ? $study->id : $study);
|
|
|
|
return 'reports/' . substr($hash, 0, 2) . '/' . substr($hash, 2, 2) . '/' . substr($hash, 4, 2);
|
|
}
|
|
|
|
public static function reportFilepath(Study|int $study, string $ext = '.html'): string
|
|
{
|
|
$directory = self::studyFolder($study);
|
|
$filename = Str::random(16) . $ext;
|
|
|
|
return $directory . '/' . $filename;
|
|
}
|
|
}
|