Get $_SERVER merged with user attributes (if available), and set
username/userAttrs properties.

<code>
$_SERVER = $sp->mergeAttrs($_SERVER);
</code>

@param array $server
@return array
480269
public function mergeAttrs($server)
    {
        $authResult = $this->getValidAuthResult();
        if ($authResult) {
            $this->userAttrs = $authResult->getAttrs();
            $server = array_merge($server, $this->userAttrs);
            if (! empty($this->_config->shibIdentityProvider)) {
                $server['Shib-Identity-Provider'] = $this->_config->shibIdentityProvider;
            }
            $server['REMOTE_USER'] = $this->username = $authResult->getUsername();
            $server['Shib-Session-ID'] = $this->_stateMgr->getSessionId();
        }
        return $server;
    }
457849
public static function marshalHeaders(array $server)
    {
        $headers = array();
        foreach ($server as $key => $value) {
            if (strpos($key, 'HTTP_COOKIE') === 0) {
                // Cookies are handled using the $_COOKIE superglobal
                continue;
            }

            if ($value && strpos($key, 'HTTP_') === 0) {
                $name = strtr(substr($key, 5), '_', ' ');
                $name = strtr(ucwords(strtolower($name)), ' ', '-');
                $name = strtolower($name);

                $headers[$name] = $value;
                continue;
            }

            if ($value && strpos($key, 'CONTENT_') === 0) {
                $name = substr($key, 8); // Content-
                $name = 'Content-' . (($name == 'MD5') ? $name : ucfirst(strtolower($name)));
                $name = strtolower($name);
                $headers[$name] = $value;
                continue;
            }
        }

        return $headers;
    }
72660
public function getHTTPHeaders(\Sabre\DAV\Server $server)
    {
        $methods = $server->getAllowedMethods($server->getRequestUri());

        return [
            'Allow' => strtoupper(implode(', ', $methods)),
        ];
    }
1018845
public function createServerRequestFromArray(array $server)
    {
        return new ServerRequest(
            $server['REQUEST_METHOD'] ?? 'GET', 
            $server['REQUEST_URI'], 
            $this->getHeadersFromServerArr($server),
            null,
            $server['SERVER_PROTOCOL'] ?? 'HTTP/1.1',
            $server
        );
    }
693924
protected function getHeadersFromServerArr(array $server) : array
    {
        $headers = [];
        $specialKeys = [
            'CONTENT_TYPE'   => 'Content-Type',
            'CONTENT_LENGTH' => 'Content-Length',
        ];
        foreach ($server as $key => $value) {
            if (substr($key, 0, 5) === 'HTTP_') {
                $header = str_replace(' ', '-',
                    ucwords(str_replace('_', ' ', strtolower(substr($key, 5))))
                );
                $headers[$header] = $value;
            } elseif (isset($specialKeys[$key])) {
                $headers[$specialKeys[$key]] = $value;
            }
        }
        
        if (!isset($headers['Authorization']) && isset($server['REDIRECT_HTTP_AUTHORIZATION'])) {
            $headers['Authorization'] = $server['REDIRECT_HTTP_AUTHORIZATION'];
        }
        
        if (isset($server['PHP_AUTH_USER'])) {
            $headers['PHP_AUTH_USER'] = $server['PHP_AUTH_USER'];
            $headers['PHP_AUTH_PW'] = $server['PHP_AUTH_PW'] ?? '';
        }
        
        return $headers;
    }
678363
public function parseServerString($server)
    {
        $socketTransport = 'unix://';
        if (strpos($server, $socketTransport) === 0) {
            return [substr($server, strlen($socketTransport)), 0];
        }
        if (substr($server, 0, 1) === '[') {
            $position = strpos($server, ']:');
            if ($position !== false) {
                $position++;
            }
        } else {
            $position = strpos($server, ':');
        }
        $port = 11211;
        $host = $server;
        if ($position !== false) {
            $host = substr($server, 0, $position);
            $port = substr($server, $position + 1);
        }

        return [$host, (int)$port];
    }
121442
public static function capture(array $server = null)
    {
        if (!$server) {
            $server = $_SERVER;
        }

        $source = 'http:';
        if (isset($server['HTTPS']) && $server['HTTPS'] && $server['HTTPS'] != 'off') {
            $source = 'https:';
        }
        if (isset($server['HTTP_HOST'])) {
            $source .= '//' . $server['HTTP_HOST'];
        }
        if (isset($server['REQUEST_URI'])) {
            $source .= $server['REQUEST_URI'];
        }

        $url = new static($source);
        $url->username = $server['PHP_AUTH_USER'] ?? null;
        $url->password = $server['PHP_AUTH_PW'] ?? null;

        return $url;
    }
100988
public static function make(array $server = null)
    {
        if (empty($server)) {
            $server = $_SERVER;
        }

        if (isset($server['REQUEST_URI'])) {
            return parse_url($server['REQUEST_URI'], PHP_URL_QUERY);
        }
    }
141411
private static function fetchHostname(array $server): array
    {
        $server += ['SERVER_PORT' => null];
        if (null !== $server['SERVER_PORT']) {
            $server['SERVER_PORT'] = (int) $server['SERVER_PORT'];
        }

        if (isset($server['HTTP_HOST'])) {
            preg_match(',^(?<host>(\[.*\]|[^:])*)(\:(?<port>[^/?\#]*))?$,x', $server['HTTP_HOST'], $matches);

            return [
                $matches['host'],
                isset($matches['port']) ? (int) $matches['port'] : $server['SERVER_PORT'],
            ];
        }

        if (!isset($server['SERVER_ADDR'])) {
            throw new SyntaxError('The host could not be detected');
        }

        if (false === filter_var($server['SERVER_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
            $server['SERVER_ADDR'] = '['.$server['SERVER_ADDR'].']';
        }

        return [$server['SERVER_ADDR'], $server['SERVER_PORT']];
    }
420817
public static function instance($server = 'redis') {
        if(is_string($server)) {
            $server = conf($server);
            $server or $server = Config::getx('redis');
        }
        $key = $server['host'] . $server['port'].$server['db'];
        if($obj = Pool::get($key)) {
            return $obj;
        }
        $pconnect = isset($server['connect'])?$server['connect']:false;
        $obj = get_called_class()?:'nb\\utility\\Redis';
        return Pool::object($key,$obj,[
            $server['host'],$server['port'],$server['db'],$pconnect
        ]);
    }
398511
public function userMapping($server)
    {
        foreach (['userName', 'firstName', 'lastName', 'email'] as $field) {
            if (!(isset($server[$field]) && '' !== $server[$field])) {
                return false;
            }
        }

        return true;
    }
1052463
protected static function resolveAuthority($server)
    {
        $authority = static::resolveHostPort($server);

        if (($userInfo = static::resolveUserInfo($server)) !== '') {
            $authority = $userInfo . '@' . $authority;
        }

        return $authority;
    }
6284
public static function getHeadersFromServer(array $server): array
    {
        $headers = [];
        foreach ($server as $key => $value) {
            // Apache prefixes environment variables with REDIRECT_
            // if they are added by rewrite rules
            if (0 === \strpos($key, 'REDIRECT_')) {
                $key = \substr($key, 9);

                // We will not overwrite existing variables with the
                // prefixed versions, though
                if (\array_key_exists($key, $server)) {
                    continue;
                }
            }

            if ($value && 0 === \strpos($key, 'HTTP_')) {
                $name = \strtr(\strtolower(\substr($key, 5)), '_', '-');
                $headers[$name] = $value;

                continue;
            }

            if ($value && 0 === \strpos($key, 'CONTENT_')) {
                $name = 'content-'.\strtolower(\substr($key, 8));
                $headers[$name] = $value;

                continue;
            }
        }

        return $headers;
    }
532726
public function initialize(Server $server)
    {
        $this->server = $server;
        $server->on('method:GET', [$this, 'httpGet']);
        $server->on('method:OPTIONS', [$this, 'httpOptions']);
        $server->on('method:HEAD', [$this, 'httpHead']);
        $server->on('method:DELETE', [$this, 'httpDelete']);
        $server->on('method:PROPFIND', [$this, 'httpPropFind']);
        $server->on('method:PROPPATCH', [$this, 'httpPropPatch']);
        $server->on('method:PUT', [$this, 'httpPut']);
        $server->on('method:MKCOL', [$this, 'httpMkcol']);
        $server->on('method:MOVE', [$this, 'httpMove']);
        $server->on('method:COPY', [$this, 'httpCopy']);
        $server->on('method:REPORT', [$this, 'httpReport']);

        $server->on('propPatch', [$this, 'propPatchProtectedPropertyCheck'], 90);
        $server->on('propPatch', [$this, 'propPatchNodeUpdate'], 200);
        $server->on('propFind', [$this, 'propFind']);
        $server->on('propFind', [$this, 'propFindNode'], 120);
        $server->on('propFind', [$this, 'propFindLate'], 200);

        $server->on('exception', [$this, 'exception']);
    }
177423
public static function fromArray(array $server)
    {
        $uri = new self('');

        if (isset($server['HTTPS'])) {
            $uri->scheme = $server['HTTPS'] === 'on' ? 'https' : 'http';
        }

        [$host, $port] = Helpers::getHostAndPortFromArray($server);

        $uri->host = \strtolower($host);
        $uri->port = $uri->filterPort($port);

        $path = Helpers::getRequestUri($server);

        $fragment = '';
        if (\strpos($path, '#') !== false) {
            [$path, $fragment] = \explode('#', $path, 2);
        }

        $uri->path = $uri->filterPath(\explode('?', $path, 2)[0]);
        $uri->fragment = $uri->filterFragment($fragment);

        if (isset($server['QUERY_STRING'])) {
            $uri->query = $uri->filterQuery($server['QUERY_STRING']);
        }

        return $uri;
    }
1054520
private static function fetchRequestUri(array $server): array
    {
        $server += ['IIS_WasUrlRewritten' => null, 'UNENCODED_URL' => '', 'PHP_SELF' => '', 'QUERY_STRING' => null];
        if ('1' === $server['IIS_WasUrlRewritten'] && '' !== $server['UNENCODED_URL']) {
            return explode('?', $server['UNENCODED_URL'], 2) + [1 => null];
        }

        if (isset($server['REQUEST_URI'])) {
            [$path, ] = explode('?', $server['REQUEST_URI'], 2);
            $query = ('' !== $server['QUERY_STRING']) ? $server['QUERY_STRING'] : null;

            return [$path, $query];
        }

        return [$server['PHP_SELF'], $server['QUERY_STRING']];
    }
1371473
private function determineHeader(array $server): MapInterface
    {
        $header = new Map();

        foreach ($server as $name => $value) {
            if (strpos($name, 'HTTP_') === 0) {
                $name = substr($name, 5);
                $name = explode('_', $name);
                $name = array_map('strtolower', $name);
                $name = array_map('ucfirst', $name);
                $name = implode('-', $name);

                $header->set($name, $value);
            }
        }

        return new ReadOnlyMap($header);
    }