Convert a PSR-7 uploaded files structure to a $_FILES structure.

@param array $uploadedFiles Array of file objects.

@return array
779190
private static function convertUploadedFiles(array $uploadedFiles)
    {
        $files = [];
        foreach ($uploadedFiles as $name => $uploadedFile) {
            if (!is_array($uploadedFile)) {
                $files[$name] = self::convertUploadedFile($uploadedFile);
                continue;
            }

            $files[$name] = [];
            foreach ($uploadedFile as $file) {
                $files[$name][] = self::convertUploadedFile($file);
            }
        }

        return $files;
    }
1194489
protected function ungroupUploadedFiles(array $uploadedFiles)
    {
        foreach (array_keys($this->files) as $key) {
            unset($this->files[$key]);
        }

        foreach ($uploadedFiles as $key => $item) {
            if (is_array($item)) {
                $group = array_fill_keys(['name', 'type', 'size', 'tmp_name', 'error'], []);
                $this->ungroupUploadedFilesDeep($item, $group['name'], $group['type'], $group['size'],
                    $group['tmp_name'], $group['error']);
                
                $this->files[$key] = $group;
            } elseif ($item instanceof UploadedFileInterface) {
                try {
                    $stream = $item->getStream();
                } catch (\RuntimeException $e) {
                    $stream = null;
                }
                
                $this->files[$key] = [
                    'name' => $item->getClientFilename(),
                    'type' => $item->getClientMediaType(),
                    'size' => $item->getSize(),
                    'tmp_name' => $stream ? $stream->getMetadata('uri') : null,
                    'error' => $item->getError()
                ];
            }
        }
    }
717582
protected static function getFlattenFileData(array $files = [])
    {
        $return = [];

        foreach (array_keys($files['tmp_name']) as $key) {
            $file = [
                'tmp_name' => $files['tmp_name'][$key],
                'size' => $files['size'][$key],
                'error' => $files['error'][$key],
                'name' => $files['name'][$key],
                'type' => $files['type'][$key],
            ];

            $return[$key] = self::createUploadedFile($file);
        }

        return $return;
    }
1359152
public function createUploadedFileFromServer(array $files)
        {
            $normalized = [];
            foreach ($files as $key => $value) {
                
                if (!isset($value['error'])) {
                    if (is_array($value)) {
                        $normalized[$key] = $this->createUploadedFileFromServer($value);
                    }
                    continue;
                }
                
                $normalized[$key] = [];
                if (!is_array($value['error'])) {

                    if ($value['error'] === 4) {
                        $stream = (new StreamFactory)->createStream('');
                    } else {
                        $stream = (new StreamFactory)->createStreamFromFile($value['tmp_name'], 'r');    
                    }
                    
                    $normalized[$key] = $this->createUploadedFile(
                        $stream,
                        $value['size'],
                        $value['error'],
                        $value['name'],
                        $value['type']
                    );

                } else {

                    $sub = [];
                    foreach ($value['error'] as $id => $error) {
   
                        $sub[$id]['name']     = $value['name'][$id];
                        $sub[$id]['type']     = $value['type'][$id];
                        $sub[$id]['tmp_name'] = $value['tmp_name'][$id];
                        $sub[$id]['error']    = $value['error'][$id];
                        $sub[$id]['size']     = $value['size'][$id];
                        
                        $normalized[$key] = $this->createUploadedFileFromServer($sub);
                    
                    }

                }

            }
            return $normalized;
        }
963059
protected function convertToUploadedFileObjects(array $files): array
	{
		$uploadedFiles = [];

		foreach($files as $name => $file)
		{
			if(is_array($file['name']))
			{
				foreach($this->normalizeMultiUpload($file) as $file)
				{
					$uploadedFiles[$name][] = $this->createUploadedFile($file);
				}
			}
			else
			{
				$uploadedFiles[$name] = $this->createUploadedFile($file);
			}
		}

		return $uploadedFiles;
	}
607083
private function SortFilesByVersion(array $files)
    {
        $result = array();
        $foreignKeysFile = '';
        foreach ($files as $file)
        {
            if ($file == 'foreign-keys.sql')
            {
                $foreignKeysFile = $file;
                continue;
            }
            $version = Path::RemoveExtension($file);
            if ($this->installedVersion && version_compare($version, $this->installedVersion) <= 0)
            {
                continue;
            }
            $result[$version] = $file;
        }
        uksort($result, "version_compare");
        if ($foreignKeysFile)
        {
            $result[] = $foreignKeysFile;
        }
        return $result;
    }
408721
public function withUploadedFiles(array $uploadedFiles)
    {
        $new        = clone $this;
        $new->files = clone $this->files;
        $files      = [];
        foreach ($uploadedFiles as $file) {
            /** @var UploadedFileInterface $file */
            $filename = tempnam(sys_get_temp_dir(), 'upload');
            $handle   = fopen($filename, 'wb');
            fwrite($handle, $file->getStream()->getContents());
            fclose($handle);
            $files[] = new UploadedFile(
                $filename,
                $file->getClientFilename(),
                $file->getClientMediaType(),
                $file->getSize(),
                $file->getError()
            );
        }
        $new->files->add($files);

        return $new;
    }
192801
public function upload($uploadedFile)
    {
        if ($uploadedFile->isValid()) {
            $this->getFilesystem()->putFileAs(
                dirname($this->getPath()),
                $uploadedFile,
                $this->getName()
            );

            return true;
        } else {
            $this->errors['upload'] = $uploadedFile->getErrorMessage();
        }

        return false;
    }
968665
private function getPhpFiles(array $committedFiles)
    {
        /**
         * @var PhpFilesResponse
         */
        $phpFilesResponse = $this->queryBus->handle(new PhpFilesExtractor($committedFiles));

        return $phpFilesResponse->getFiles();
    }
952427
protected function getFilename(UploadedFile $uploadedFile)
    {
        $extension = $uploadedFile->guessExtension();
        $filename = str_random().'.'.$extension;

        return $filename;
    }
1345629
public function getFileFromChunks(UploadedFile $uploadedFile)
    {
        $filename = time() . '-' . $uploadedFile->getClientOriginalName();
        $path = $this->tmpDir . DIRECTORY_SEPARATOR . $filename;

        if (FlowBasic::save($path, $this->tmpDir)) {
            return new UploadedFile($path, $uploadedFile->getClientOriginalName(), $uploadedFile->getClientMimeType());
        }

        return null;
    }
984969
private function uploadMore(array $files)
    {
        $res = [];
        foreach ($files as $file) {
            $result = $this->uploadOne($file);
            $res[] = $result;
        }
        return $res;
    }
1333491
public function compactFiles(array $files, $uploadDir)
    {
        if ($this->type !== self::TYPE_FILE) {
            throw FormFieldException::notAFileUpload($this->tagName);
        }

        if (empty($files)) {
            throw new NoFileUploadedException("Files are missing from payload");
        }

        foreach (UploadedFile::create($this->name, $files, $uploadDir) as $uploadedFile) {
            $this->files[] = $uploadedFile;
        }
    }
430238
public function upload(UploadedFile $file = null)
    {
        if ($file === null) {
            return '';
        }

        $fileName = $this->getFileName($file);
        $file->move($this->getTargetDir(), $fileName);

        return $fileName;
    }
816146
protected function diverse(array $uploaded)
    {
        $result = array();

        foreach ($uploaded as $file => $item)
        {
            foreach ($item as $key => $value)
            {
                $diversed = (array) $value;

                $result[$file][$key] = $diversed;
            }
        }

        return $result;
    }
1236860
private function getFiles(array $uploadedFiles)
    {
        $files = [];

        foreach ($uploadedFiles as $key => $value) {
            if (null === $value) {
                $files[$key] = $this->uploadedFileFactory->createUploadedFile($this->streamFactory->createStream(), 0, UPLOAD_ERR_NO_FILE);
                continue;
            }
            if ($value instanceof UploadedFile) {
                $files[$key] = $this->createUploadedFile($value);
            } else {
                $files[$key] = $this->getFiles($value);
            }
        }

        return $files;
    }
998445
private function uploadOne(UploadedFile $file)
    {
        try {
            $uploader = new Uploader(['config' => $this->_config]);
            $uploader->up($file);
            $fileInfo = $uploader->getFileInfo();
            $result = [
                'name' => Html::encode($file->name),
                'url' => $fileInfo['url'],
                'path' => $fileInfo['url'],
                'extension' => $file->extension,
                'type' => $file->type,
                'size' => $file->size
            ];
            if ($this->onlyImage !== true) {
                $result['filename'] = $result['name'];
            }

        } catch (Exception $e) {
            $result = [
                'error' => $e->getMessage()
            ];
        }
        return $result;
    }