path; } public function __construct(protected string $path, protected FilesystemAdapter $disk) { $this->path = Str::start(Str::finish($this->path, '/'), '/'); $this->dataDir = $this->path . 'data/'; $this->registerDefaultManagers(); } /** * Load everything */ public function load() { $this->loadAttachments(); $this->loadMetadata(); $this->loadMarkdown(); } /** * Store all files of the bundle */ public function save() { $this->saveAttachments(); $this->saveMetadata(); $this->saveMarkdown(); } /** * Register default managers */ private function registerDefaultManagers() { $this->markdown(); $this->metadata(); $this->metadata('metadata'); $this->attachments(AttachmentsManager::Images); $this->attachments(AttachmentsManager::Sounds); $this->attachments(AttachmentsManager::Videos); } /** * Get a complete filename prefixed with bundle's path */ private function getFilenameInBundle(string $filename, ?string $extension = null) { return $this->getFullpath($this->path, $filename, $extension); } /** * Get a complete filename prefixed with bundle's data dir */ private function getFilenameInDataBundle(string $filename, ?string $extension = null) { return $this->getFullpath($this->dataDir, $filename, $extension); } /** * Return full path of specified filename in specified root directory, and * optionally add specified extension */ private function getFullpath(string $root, string $filename, ?string $extension = null) { $filename = Str::remove($root, $filename); if (!empty($extension) && !Str::endsWith($filename, $extension)) { $filename .= $extension; } return sprintf('%s%s', $root, $filename); } /** * Return a boolean value indicating if there already is a bundle in * specified path */ public function 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; } } }