%PDF- %PDF-filesystem = $filesystem; $this->rootWrite = $filesystem->getDirectoryWrite(DirectoryList::ROOT); $this->rootRead = $filesystem->getDirectoryRead(DirectoryList::ROOT); } public function deployFolder($folder) { $from = $this->rootRead->getRelativePath($folder); $this->moveFilesFromTo($from, ''); } public function moveFilesFromTo($fromPath, $toPath) { //phpcs:ignore $baseName = basename($fromPath); $files = $this->rootRead->readRecursively($fromPath); array_unshift($files, $fromPath); foreach ($files as $file) { $newFileName = $this->getNewFilePath( $file, $fromPath, ltrim($toPath . '/' . $baseName, '/') ); if ($this->rootRead->isExist($newFileName)) { continue; } if ($this->rootRead->isFile($file)) { $this->rootWrite->copyFile($file, $newFileName); $this->rootWrite->changePermissions( $newFileName, self::DEFAULT_FILE_PERMISSIONS ); } elseif ($this->rootRead->isDirectory($file)) { $this->rootWrite->create($newFileName); $this->rootWrite->changePermissions( $newFileName, self::DEFAULT_DIR_PERMISSIONS ); } } } protected function getNewFilePath($filePath, $fromPath, $toPath) { return str_replace($fromPath, $toPath, $filePath); } }