get(TargetDirectory::class); $filesystem = $filesystem ?: ObjectManager::getInstance()->get(FileSystem::class); $config = $config ?: ObjectManager::getInstance()->get(Config::class); if ($config->isEnabled() && isset($fileId['tmp_name'])) { $this->tmpDirectoryWrite = $filesystem->getDirectoryWrite(DirectoryList::TMP); $this->remoteDirectoryWrite = $targetDirectory->getDirectoryWrite(DirectoryList::ROOT); $fileId['tmp_name'] = $this->copyFileToTmp($fileId['tmp_name']); } parent::__construct($fileId, $fileMime, $directoryList, $driverPool, $targetDirectory, $filesystem); } /** * Moves file from the remote storage to the tmp folder * * @param string $filePath * @return string * @throws FileSystemException */ private function copyFileToTmp(string $filePath): string { $absolutePath = $this->remoteDirectoryWrite->getAbsolutePath($filePath); if ($this->remoteDirectoryWrite->isFile($absolutePath)) { $this->tmpDirectoryWrite->create(); // phpcs:ignore Magento2.Functions.DiscouragedFunction $tmpPath = $this->tmpDirectoryWrite->getAbsolutePath() . basename($filePath); $content = $this->remoteDirectoryWrite->getDriver()->fileGetContents($filePath); $this->tmpDirectoryWrite->getDriver()->filePutContents($tmpPath, $content); return $tmpPath; } return $filePath; } }