src/Viserio/Component/Http/Util.php
public static function normalizeFiles(array $files): array
    {
        /**
         * @param array[]|string[]      $tmpNameTree
         * @param array[]|int[]         $sizeTree
         * @param array[]|int[]         $errorTree
         * @param null|array[]|string[] $nameTree
         * @param null|array[]|string[] $typeTree
         *
         * @return array[]|\Psr\Http\Message\UploadedFileInterface[]
         */
        $recursiveNormalize = static function (
            array $tmpNameTree,
            array $sizeTree,
            array $errorTree,
            array $nameTree = null,
            array $typeTree = null
        ) use (&$recursiveNormalize) {
            $normalized = [];

            foreach ($tmpNameTree as $key => $value) {
                if (\is_array($value)) {
                    // Traverse
                    $normalized[$key] = $recursiveNormalize(
                        $tmpNameTree[$key],
                        $sizeTree[$key],
                        $errorTree[$key],
                        $nameTree[$key] ?? null,
                        $typeTree[$key] ?? null
                    );

                    continue;
                }

                $normalized[$key] = self::createUploadedFileFromSpec([
                    'tmp_name' => $tmpNameTree[$key],
                    'size'     => $sizeTree[$key],
                    'error'    => $errorTree[$key],
                    'name'     => $nameTree[$key] ?? null,
                    'type'     => $typeTree[$key] ?? null,
                ]);
            }

            return $normalized;
        };

        /**
         * Normalize an array of file specifications.
         *
         * Loops through all nested files (as determined by receiving an array to the
         * `tmp_name` key of a `$_FILES` specification) and returns a normalized array
         * of UploadedFile instances.
         *
         * This function normalizes a `$_FILES` array representing a nested set of
         * uploaded files as produced by the php-fpm SAPI, CGI SAPI, or mod_php
         * SAPI.
         *
         * @param array $files
         *
         * @return \Psr\Http\Message\UploadedFileInterface[]
         */
        $normalizeUploadedFileSpecification = static function (array $files = []) use (&$recursiveNormalize) {
            if (! isset($files['tmp_name']) || ! \is_array($files['tmp_name']) ||
                ! isset($files['size']) || ! \is_array($files['size']) ||
                ! isset($files['error']) || ! \is_array($files['error'])
            ) {
                throw new InvalidArgumentException(\sprintf(
                    '$files provided to %s MUST contain each of the keys "tmp_name",'
                    . ' "size", and "error", with each represented as an array;'
                    . ' one or more were missing or non-array values',
                    __FUNCTION__
                ));
            }

            return $recursiveNormalize(
                $files['tmp_name'],
                $files['size'],
                $files['error'],
                $files['name'] ?? null,
                $files['type'] ?? null
            );
        };

        $normalized = [];

        foreach ($files as $key => $value) {
            if ($value instanceof UploadedFileInterface) {
                $normalized[$key] = $value;

                continue;
            }

            if (\is_array($value) && isset($value['tmp_name']) && \is_array($value['tmp_name'])) {
                $normalized[$key] = $normalizeUploadedFileSpecification($value);

                continue;
            }

            if (\is_array($value) && isset($value['tmp_name'])) {
                $normalized[$key] = self::createUploadedFileFromSpec($value);

                continue;
            }

            if (\is_array($value)) {
                $normalized[$key] = self::normalizeFiles($value);

                continue;
            }

            throw new InvalidArgumentException('Invalid value in files specification.');
        }

        return $normalized;
    }
public static function normalizeFiles(array $files): array
    {
        /**
         * @param array[]|string[]      $tmpNameTree
         * @param array[]|int[]         $sizeTree
         * @param array[]|int[]         $errorTree
         * @param null|array[]|string[] $nameTree
         * @param null|array[]|string[] $typeTree
         *
         * @return array[]|\Psr\Http\Message\UploadedFileInterface[]
         */
        $recursiveNormalize = static function (
            array $tmpNameTree,
            array $sizeTree,
            array $errorTree,
            array $nameTree = null,
            array $typeTree = null
        ) use (&$recursiveNormalize) {
            $normalized = [];

            foreach ($tmpNameTree as $key => $value) {
                if (\is_array($value)) {
                    // Traverse
                    $normalized[$key] = $recursiveNormalize(
                        $tmpNameTree[$key],
                        $sizeTree[$key],
                        $errorTree[$key],
                        $nameTree[$key] ?? null,
                        $typeTree[$key] ?? null
                    );

                    continue;
                }

                $normalized[$key] = self::createUploadedFileFromSpec([
                    'tmp_name' => $tmpNameTree[$key],
                    'size'     => $sizeTree[$key],
                    'error'    => $errorTree[$key],
                    'name'     => $nameTree[$key] ?? null,
                    'type'     => $typeTree[$key] ?? null,
                ]);
            }

            return $normalized;
        };

        /**
         * Normalize an array of file specifications.
         *
         * Loops through all nested files (as determined by receiving an array to the
         * `tmp_name` key of a `$_FILES` specification) and returns a normalized array
         * of UploadedFile instances.
         *
         * This function normalizes a `$_FILES` array representing a nested set of
         * uploaded files as produced by the php-fpm SAPI, CGI SAPI, or mod_php
         * SAPI.
         *
         * @param array $files
         *
         * @return \Psr\Http\Message\UploadedFileInterface[]
         */
        $normalizeUploadedFileSpecification = static function (array $files = []) use (&$recursiveNormalize) {
            if (! isset($files['tmp_name']) || ! \is_array($files['tmp_name']) ||
                ! isset($files['size']) || ! \is_array($files['size']) ||
                ! isset($files['error']) || ! \is_array($files['error'])
            ) {
                throw new InvalidArgumentException(\sprintf(
                    '$files provided to %s MUST contain each of the keys "tmp_name",'
                    . ' "size", and "error", with each represented as an array;'
                    . ' one or more were missing or non-array values',
                    __FUNCTION__
                ));
            }

            return $recursiveNormalize(
                $files['tmp_name'],
                $files['size'],
                $files['error'],
                $files['name'] ?? null,
                $files['type'] ?? null
            );
        };

        $normalized = [];

        foreach ($files as $key => $value) {
            if ($value instanceof UploadedFileInterface) {
                $normalized[$key] = $value;

                continue;
            }

            if (\is_array($value) && isset($value['tmp_name']) && \is_array($value['tmp_name'])) {
                $normalized[$key] = $normalizeUploadedFileSpecification($value);

                continue;
            }

            if (\is_array($value) && isset($value['tmp_name'])) {
                $normalized[$key] = self::createUploadedFileFromSpec($value);

                continue;
            }

            if (\is_array($value)) {
                $normalized[$key] = self::normalizeFiles($value);

                continue;
            }

            throw new InvalidArgumentException('Invalid value in files specification.');
        }

        return $normalized;
    }
Return an UploadedFile instance array.

@param array $files A array which respect $_FILES structure

@throws \Viserio\Component\Contract\Http\Exception\InvalidArgumentException for unrecognized values

@return array