mirror of
https://github.com/brufdev/many-notes.git
synced 2026-01-24 20:09:50 -06:00
45 lines
1.0 KiB
PHP
45 lines
1.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Actions;
|
|
|
|
use App\Models\User;
|
|
use App\Models\Vault;
|
|
use App\Models\VaultNode;
|
|
|
|
final readonly class GetPathFromVaultNode
|
|
{
|
|
public function handle(VaultNode $node, bool $includeSelf = true): string
|
|
{
|
|
/** @var Vault $vault */
|
|
$vault = $node->vault;
|
|
/** @var User $user */
|
|
$user = $vault->user;
|
|
$relativePath = '';
|
|
|
|
if ($node->parent) {
|
|
/**
|
|
* @var string $fullPath
|
|
*
|
|
* @phpstan-ignore-next-line larastan.noUnnecessaryCollectionCall
|
|
*/
|
|
$fullPath = $node->parent->ancestorsAndSelf()->get()->last()->full_path;
|
|
$relativePath = $fullPath . '/';
|
|
}
|
|
|
|
$path = sprintf(
|
|
'private/vaults/%u/%s/%s',
|
|
$user->id,
|
|
$vault->name,
|
|
$relativePath,
|
|
);
|
|
|
|
if ($includeSelf) {
|
|
$path .= $node->name . ($node->is_file ? '.' . $node->extension : '');
|
|
}
|
|
|
|
return $path;
|
|
}
|
|
}
|