Esempio n. 1
0
File: Mock.php Progetto: seytar/psx
 public function request(RequestInterface $request, Options $options)
 {
     $url = $request->getUri();
     foreach ($this->resources as $resource) {
         $resourceUrl = new Url($resource['url']);
         if ($resource['method'] == $request->getMethod() && $resourceUrl->getHost() == $url->getHost() && $resourceUrl->getPath() == $url->getPath() && $resourceUrl->getQuery() == $url->getQuery()) {
             $response = $resource['handler']($request);
             return ResponseParser::convert($response);
         }
     }
     throw new Exception('Resource not available ' . $request->getMethod() . ' ' . $url);
 }
Esempio n. 2
0
 public function hasProject($url)
 {
     $url = new Url($url);
     if ($url->getHost() != 'github.com') {
         return false;
     }
     $parts = explode('/', trim($url->getPath(), '/'));
     if (count($parts) != 2) {
         return false;
     }
     $request = new GetRequest($url);
     $response = $this->http->request($request);
     return $response->getCode() == 200;
 }
Esempio n. 3
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);
 }