2026-11-03 12:26:17 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Uwil\Storage\Lib\PathGenerators;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
use Uwil\Storage\Contracts\PathGenerator;
|
|
|
|
|
use Uwil\Storage\Lib\ValueObjects\DiskName;
|
|
|
|
|
use Uwil\Storage\Lib\ValueObjects\SanitizedFile;
|
|
|
|
|
use Uwil\Storage\Lib\ValueObjects\StorageFilePath;
|
|
|
|
|
|
|
|
|
|
class UuidPathGenerator implements PathGenerator
|
|
|
|
|
{
|
|
|
|
|
#[\Override]
|
|
|
|
|
public function generate(DiskName $disk, SanitizedFile $file, ?string $directory = null): StorageFilePath
|
|
|
|
|
{
|
|
|
|
|
$extension = pathinfo($file->sanitizedName, PATHINFO_EXTENSION);
|
2026-11-03 15:49:02 +01:00
|
|
|
$uuid = Str::uuid()->toString();
|
2026-11-03 12:26:17 +01:00
|
|
|
|
2026-11-03 15:49:02 +01:00
|
|
|
$finalFilename = $uuid . (! empty($extension) ? '.' . $extension : '');
|
2026-11-03 12:26:17 +01:00
|
|
|
|
|
|
|
|
$pathSegments = array_filter([
|
|
|
|
|
$directory ? trim($directory, '/') : null,
|
|
|
|
|
$finalFilename,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return new StorageFilePath(implode('/', $pathSegments));
|
|
|
|
|
}
|
|
|
|
|
}
|