adrema/app/Fileshare/Data/ResourceData.php

25 lines
510 B
PHP
Raw Normal View History

2024-06-28 23:56:34 +02:00
<?php
namespace App\Fileshare\Data;
use Spatie\LaravelData\Data;
class ResourceData extends Data
{
2024-06-29 11:18:40 +02:00
public function __construct(public string $name, public string $path, public string $parent)
2024-06-28 23:56:34 +02:00
{
}
public static function fromString(string $path): self
{
$dir = '/' . trim($path, '\\/');
return self::from([
'path' => $dir,
'name' => pathinfo($dir, PATHINFO_BASENAME),
2024-06-28 23:56:34 +02:00
'parent' => pathinfo($dir, PATHINFO_DIRNAME),
]);
}
}