1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <?php protected function getAndCreateFolder(string $folderPath): Folder { if ($this->storage->hasFolder($folderPath)) { return $this->storage->getFolder($folderPath); } $folder = $this->storage->getRootLevelFolder(false); $parts = explode('/', $folderPath); foreach ($parts as $part) { if (!$this->storage->hasFolderInFolder($part, $folder)) { $folder = $this->storage->createFolder($part, $folder); } else { $folder = $this->storage->getFolderInFolder($part, $folder); } } return $folder; } |