Provides a way to list bundles
This commit is contained in:
parent
b14be6c70b
commit
5b9f4eeead
|
@ -7,6 +7,7 @@
|
||||||
use App\Classes\Traits\ManagesMetadata;
|
use App\Classes\Traits\ManagesMetadata;
|
||||||
use Illuminate\Filesystem\FilesystemAdapter;
|
use Illuminate\Filesystem\FilesystemAdapter;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use League\Flysystem\StorageAttributes;
|
||||||
|
|
||||||
class Bundle
|
class Bundle
|
||||||
{
|
{
|
||||||
|
@ -14,6 +15,11 @@ class Bundle
|
||||||
|
|
||||||
protected string $dataDir;
|
protected string $dataDir;
|
||||||
|
|
||||||
|
public function getPath()
|
||||||
|
{
|
||||||
|
return $this->path;
|
||||||
|
}
|
||||||
|
|
||||||
public function __construct(protected string $path, protected FilesystemAdapter $disk)
|
public function __construct(protected string $path, protected FilesystemAdapter $disk)
|
||||||
{
|
{
|
||||||
$this->path = Str::start(Str::finish($this->path, '/'), '/');
|
$this->path = Str::start(Str::finish($this->path, '/'), '/');
|
||||||
|
@ -94,4 +100,28 @@ public function exists()
|
||||||
{
|
{
|
||||||
return $this->markdown()->exists();
|
return $this->markdown()->exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function findBundles(FilesystemAdapter $disk, ?string $path = '/', bool $recursive = false)
|
||||||
|
{
|
||||||
|
if ($recursive) {
|
||||||
|
return $disk
|
||||||
|
->listContents($path, $recursive)
|
||||||
|
->filter(fn (StorageAttributes $attributes) => ($attributes->isFile() && Str::endsWith($attributes->path(), '.md')))
|
||||||
|
->map(fn (StorageAttributes $attributes) => new Bundle(dirname($attributes->path()), $disk))
|
||||||
|
->toArray();
|
||||||
|
} else {
|
||||||
|
$bundles = [];
|
||||||
|
$directories = $disk->directories($path);
|
||||||
|
|
||||||
|
foreach ($directories as $directory) {
|
||||||
|
$bundle = new Bundle($directory, $disk);
|
||||||
|
|
||||||
|
if ($bundle->exists()) {
|
||||||
|
$bundles[] = $bundle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $bundles;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user