Esempio n. 1
0
 /**
  * Resolves the $uri either to an PSX\OpenId\Identity if its an XRI or
  * to an PSX\Url
  *
  * @return PSX\OpenId\Identity|PSX\Url
  */
 public function normalizeUri($uri)
 {
     if (!empty($uri)) {
         $uri = strtolower($uri);
         $isXri = false;
         if (substr($uri, 0, 6) == 'xri://') {
             $uri = substr($uri, 6);
             $isXri = true;
         }
         if (in_array($uri[0], self::$xriGlobalContextSymbol)) {
             $isXri = true;
         }
         if ($isXri !== true) {
             if (substr($uri, 0, 7) != 'http://' && substr($uri, 0, 8) != 'https://') {
                 $uri = 'http://' . $uri;
             }
             $url = new Url($uri);
             if ($url->getScheme() == 'http' || $url->getScheme() == 'https') {
                 return $url;
             } else {
                 throw new Exception('Unknown protocol in identity');
             }
         } else {
             return $this->discoverXriIdentity($uri);
         }
     }
     return false;
 }
Esempio n. 2
0
File: Oauth.php Progetto: seytar/psx
 /**
  * Normalize the url like defined in
  *
  * @see http://tools.ietf.org/html/rfc5849#section-3.4.1.2
  * @param \PSX\Url $url
  * @return false|string
  */
 public static function getNormalizedUrl(Url $url)
 {
     $scheme = $url->getScheme();
     $host = $url->getHost();
     $port = $url->getPort();
     $path = $url->getPath();
     // no port for 80 (http) and 443 (https)
     if (($port == 80 || empty($port)) && strcasecmp($scheme, 'http') == 0 || ($port == 443 || empty($port)) && strcasecmp($scheme, 'https') == 0) {
         $normalizedUrl = $scheme . '://' . $host . $path;
     } else {
         if (!empty($port)) {
             $normalizedUrl = $scheme . '://' . $host . ':' . $port . $path;
         } else {
             throw new Exception('No port specified');
         }
     }
     return strtolower($normalizedUrl);
 }