Create a normalized tree of UploadedFile instances from global server variables.

@param array $globals The global server variables.

@return array|null A normalized tree of UploadedFile instances or null if none are provided.
508534
public static function createFromGlobals(array $globals)
    {
        $env = new \Sofi\Base\Collection($globals);
        if (is_array($env['slim.files']) && $env->has('slim.files')) {
            return $env['slim.files'];
        } elseif (isset($_FILES)) {
            return static::parseUploadedFiles($_FILES);
        }
        return [];
    }
1243735
private function getGlobal(string $global, string $name)
    {
        if (!isset($GLOBALS[$global]) // Global does not exist
            || !is_array($GLOBALS[$global]) // Global is not an array
            || ($name && !isset($GLOBALS[$global][$name])) // Global variable does not exist
        ) {
            return null;
        }
        if (!$name) {
            return $GLOBALS[$global]; // return entire Global array
        }

        return $GLOBALS[$global][$name]; // return requested Global variable
    }
612501
private function normalizeHeaders($headers)
    {
        if (is_array($headers)) {
            $headers = new Headers($headers);
        } elseif (!($headers instanceof Headers)) {
            throw new InvalidArgumentException(
                'Headers must be an array or instance of Headers'
            );
        }

        return $headers;
    }
394946
protected static function simulateGlobBrace( $filenames )
    {
       $result = array();

       foreach ( $filenames as $filename )
       {
           if ( strpos( $filename, '{' ) === false )
           {
               $result[] = $filename;
               continue;
           }

           if ( preg_match( '/^(.*)\{(.*?)(?<!\\\\)\}(.*)$/', $filename, $match ) )
           {
               $variants = preg_split( '/(?<!\\\\),/', $match[2] );

               $newFilenames = array();
               foreach ( $variants as $variant )
               {
                   $newFilenames[] = $match[1] . $variant . $match[3];
               }

               $newFilenames = self::simulateGlobBrace( $newFilenames );
               $result = array_merge( $result, $newFilenames );
           }
           else
           {
               $result[] = $filename;
           }
       }

       return $result;
    }
1148051
private function mergeDefaults(&$options)
    {
        // Merging optimization for when no headers are present
        if (!isset($options['headers'])
            || !isset($this->defaults['headers'])) {
            $options = array_replace_recursive($this->defaults, $options);
            return null;
        }

        $defaults = $this->defaults;
        unset($defaults['headers']);
        $options = array_replace_recursive($defaults, $options);

        return $this->defaults['headers'];
    }
801972
public static function globAll(string $baseDir, array $patterns, int $flags = 0): array
    {
        $files = [];
        $inverse = [];

        foreach ($patterns as $pattern) {
            if (strpos($pattern, '!') === 0) {
                $pattern = substr($pattern, 1);

                $inverse[] = static::glob(
                    rtrim($baseDir, '\\/') . '/' . ltrim($pattern, '\\/'),
                    $flags
                );
            } else {
                $files[] = static::glob(
                    rtrim($baseDir, '\\/') . '/' . ltrim($pattern, '\\/'),
                    $flags
                );
            }
        }

        if ($files !== []) {
            $files = array_unique(array_merge(...$files));
        }

        if ($inverse !== []) {
            $inverse = array_unique(array_merge(...$inverse));
        }

        return array_diff($files, $inverse);
    }
134715
protected function backupGlobals() {
		$this->globalsBackup = array();
		foreach($GLOBALS as $key => $value) {
			if($key != 'GLOBALS') {
				$this->globalsBackup[$key] = $value;
			}
		}
	}
1310988
private function getFiles(array $uploadedFiles)
    {
        $files = [];

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

        return $files;
    }
336917
protected function getCachedFilepath(array $vars)
	{
		if (!isset($this->cacheDir))
		{
			return null;
		}

		$filepath = $this->cacheDir . '/http.' . $this->getCacheKey($vars);
		if (extension_loaded('zlib'))
		{
			$filepath = 'compress.zlib://' . $filepath . '.gz';
		}

		return $filepath;
	}
337956
public function make_section_globals($section) {
		if(!is_null($section) && strlen($section) && in_array($section, $this->get_valid_sections())) {
			foreach($this->fullConfig[$section] as $k=>$parsedValue) {
				//TODO: implement option to set a section/value as a GLOBAL
				$GLOBALS[$k] = $parsedValue;
			}
		}
		else {
			throw InvalidArgumentException("non-existent section, '". $section ."'");
		}
	}
1074086
protected function normaliseUploadedFile($uploadedFile, $localPath, $visibility)
    {
        list ($parentId, $fileName) = $this->splitPath($localPath);

        if (!($uploadedFile instanceof Google_Service_Drive_DriveFile)) {
            return false;
        }

        $this->cacheFileObjects[$uploadedFile->getId()] = $uploadedFile;
        if (! $this->getFileObject($localPath)) {
            $this->cacheFileObjectsByName[$parentId . '/' . $fileName] = $uploadedFile;
        }
        $result = $this->normaliseObject($uploadedFile, Util::dirname($localPath));

        if ($visibility && $this->setVisibility($localPath, $visibility)) {
            $result['visibility'] = $visibility;
        }

        return $result;
    }
125576
public static function fromGlobals(
        array $server = null,
        array $query = null,
        array $body = null,
        array $cookies = null,
        array $files = null
    ) {
        $server  = \Zend\Diactoros\normalizeServer($server ?: $_SERVER);
        $files   = \Zend\Diactoros\normalizeUploadedFiles($files ?: $_FILES);
        $headers = [];
        foreach ($server as $key => $value) {
            if (strpos($key, 'REDIRECT_') === 0) {
                $key = substr($key, 9);
                if (array_key_exists($key, $server)) {
                    continue;
                }
            }
            if (is_string($value) && strlen($value) && strpos($key, 'HTTP_') === 0) {
                $name = strtr(strtolower(substr($key, 5)), '_', '-');
                $headers[$name] = $value;
                continue;
            }
            if (is_string($value) && strlen($value) && strpos($key, 'CONTENT_') === 0) {
                $name = 'content-' . strtolower(substr($key, 8));
                $headers[$name] = $value;
                continue;
            }
        }

        $method  = \Zend\Diactoros\marshalMethodFromSapi($server);
        $uri     = \Zend\Diactoros\marshalUriFromSapi($server, $headers);

        if (null === $cookies && array_key_exists('cookie', $headers)) {
            $cookies = self::parseCookieHeader($headers['cookie']);
        }
        

        if ($body === null) {
            $body = [];
            if (isset($headers['content-type']) && strpos($headers['content-type'], 'json') !== false) {
                $body = json_decode($body, true);
                if ($body === null) {
                    $body = [];
                }
            } else {
                $body = static::fixedQueryParams(file_get_contents('php://input'));
            }
        }

        return new static(
            $server,
            $files,
            $uri,
            $method,
            'php://input',
            $headers,
            $cookies ?: $_COOKIE,
            $query ?: static::fixedQueryParams($uri->getQuery()),
            $body ?: (count($_POST) ? $_POST : json_decode(file_get_contents('php://input'), true)),
            \Zend\Diactoros\marshalProtocolVersionFromSapi($server)
        );
    }
792717
public static function parseForHeadersFromGlobal(array $globals = null) : array
    {
        $globals = $globals === null ? $_SERVER : $globals;
        $globals = self::determineHeaderAuthorization($globals);
        /**
         * Special HTTP headers that do not have the "HTTP_" prefix
         *
         * @var array
         */
        $special = [
            'CONTENT_TYPE'    => 1,
            'CONTENT_LENGTH'  => 1,
            'PHP_AUTH_USER'   => 1,
            'PHP_AUTH_PW'     => 1,
            'PHP_AUTH_DIGEST' => 1,
            'AUTH_TYPE'       => 1,
        ];

        $data = [];
        foreach ($globals as $key => $value) {
            $key = strtoupper($key);
            if (isset($special[$key]) || strpos($key, 'HTTP_') === 0) {
                if ($key !== 'HTTP_CONTENT_LENGTH') {
                    $key        = self::reconstructOriginalKey($key);
                    $data[$key] = $value;
                }
            }
        }

        return $data;
    }
1174064
protected function prepareGlobals($globals)
    {
        // My kingdom for a generator.
        $ret = [];

        foreach ($globals as $name => $value) {
            if ($this->showItem($name)) {
                $fname = '$' . $name;
                $ret[$fname] = [
                    'name'  => $fname,
                    'style' => self::IS_GLOBAL,
                    'value' => $this->presentRef($value),
                ];
            }
        }

        return $ret;
    }
1077778
public function addGlobalVariables($vars)
    {
        $globalVars = $this->getGlobalVariables();
        if ($globalVars == null || empty($globalVars))
        {
            return $vars;
        }

        return array_merge($vars, $this->getGlobalVariables());
    }
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;
    }
332552
protected static function manipulateIfCLIRequest(array $globals) : array
    {
        if (php_sapi_name() !== 'cli') {
            return $globals;
        }

        global $argv;
        $args = $argv;
        !isset($args[1]) && $args[1] = '/';
        $args[1] = substr($args[1], 0, 1) !== '/'
            ? '/'. $args[1]
            : $args[1];
        $query_string = explode('?', $args[1]);
        array_shift($query_string);
        $query_string = implode('?', $query_string);

        !isset($args[2]) && $args[2] = 'GET';
        !isset($args[3]) && $args[3] = '';

        if (!isset($globals['REQUEST_URI'])) {
            $globals['REQUEST_URI'] = $args[1];
        }
        if (!isset($globals['QUERY_STRING'])) {
            $globals['QUERY_STRING'] = $query_string;
        }
        if (!isset($globals['HTTP_HOST'])) {
            $globals['HTTP_HOST'] = 'cli';
        }
        if (!isset($globals['REQUEST_METHOD'])) {
            $globals['REQUEST_METHOD'] = $args[2];
        }
        if ($args[3] !== '') {
            file_put_contents('php://input', $args[3]);
        }

        return $globals;
    }