Ejemplo n.º 1
0
 /**
  * Format a URI authority according to the Formatter properties
  *
  * @param UriInterface|Uri $uri
  *
  * @return string
  */
 protected function formatAuthority($uri)
 {
     if ('' == $uri->getHost()) {
         return '';
     }
     $components = $this->uriParser->parse((string) $uri);
     $port = $components['port'];
     if (!empty($port)) {
         $port = ':' . $port;
     }
     return '//' . $this->uriParser->buildUserInfo($components['user'], $components['pass']) . $this->formatHost(new Host($components['host'])) . $port;
 }
Ejemplo n.º 2
0
 /**
  * Returns the environment user info
  *
  * @param array $server the environment server typically $_SERVER
  *
  * @return string
  */
 protected static function fetchServerUserInfo(array $server)
 {
     $server += ['PHP_AUTH_USER' => null, 'PHP_AUTH_PW' => null, 'HTTP_AUTHORIZATION' => null];
     $parser = new UriParser();
     if (!empty($server['HTTP_AUTHORIZATION']) && 0 === strpos(strtolower($server['HTTP_AUTHORIZATION']), 'basic')) {
         $res = explode(':', base64_decode(substr($server['HTTP_AUTHORIZATION'], 6)), 2);
         $login = array_shift($res);
         $pass = array_shift($res);
         return $parser->buildUserInfo(rawurlencode($login), rawurlencode($pass));
     }
     return $parser->buildUserInfo(rawurlencode($server['PHP_AUTH_USER']), rawurlencode($server['PHP_AUTH_PW']));
 }