示例#1
0
 private static function urinorm($uri)
 {
     $uri_matches = array();
     preg_match(self::URIPattern, $uri, $uri_matches);
     if (count($uri_matches) < 9) {
         for ($i = count($uri_matches); $i <= 9; $i++) {
             $uri_matches[] = '';
         }
     }
     $illegal_matches = array();
     preg_match(self::URLIllegalCharRE, $uri, $illegal_matches);
     if ($illegal_matches) {
         return null;
     }
     $scheme = $uri_matches[2];
     if ($scheme) {
         $scheme = strtolower($scheme);
     }
     $scheme = $uri_matches[2];
     if ($scheme === '') {
         // No scheme specified
         return null;
     }
     $scheme = strtolower($scheme);
     if (!in_array($scheme, array('http', 'https'))) {
         // Not an absolute HTTP or HTTPS URI
         return null;
     }
     $authority = $uri_matches[4];
     if ($authority === '') {
         // Not an absolute URI
         return null;
     }
     $authority_matches = array();
     preg_match(self::AuthorityPattern, $authority, $authority_matches);
     if (count($authority_matches) === 0) {
         // URI does not have a valid authority
         return null;
     }
     if (count($authority_matches) < 4) {
         for ($i = count($authority_matches); $i <= 4; $i++) {
             $authority_matches[] = '';
         }
     }
     list($_whole, $userinfo, $host, $port) = $authority_matches;
     if ($userinfo === null) {
         $userinfo = '';
     }
     if (strpos($host, '%') !== -1) {
         $host = strtolower($host);
         $host = preg_replace_callback(self::EncodedPattern, function ($mo) {
             return chr(intval($mo[1], 16));
         }, $host);
         // NO IDNA.
         // $host = unicode($host, 'utf-8').encode('idna');
     } else {
         $host = strtolower($host);
     }
     if ($port) {
         if ($port == ':' || $scheme == 'http' && $port == ':80' || $scheme == 'https' && $port == ':443') {
             $port = '';
         }
     } else {
         $port = '';
     }
     $authority = $userinfo . $host . $port;
     $path = $uri_matches[5];
     $path = preg_replace_callback(self::EncodedPattern, function ($mo) {
         $_unreserved = OpenIdUriHelper::getUnreserved();
         $i = intval($mo[1], 16);
         if ($_unreserved[$i]) {
             return chr($i);
         } else {
             return strtoupper($mo[0]);
         }
         return $mo[0];
     }, $path);
     $path = self::remove_dot_segments($path);
     if (!$path) {
         $path = '/';
     }
     $query = $uri_matches[6];
     if ($query === null) {
         $query = '';
     }
     $fragment = $uri_matches[8];
     if ($fragment === null) {
         $fragment = '';
     }
     return $scheme . '://' . $authority . $path . $query . $fragment;
 }