コード例 #1
0
ファイル: Http.php プロジェクト: seytar/psx
 public function resolve(Uri $uri, Document $source, RefResolver $resolver)
 {
     if (!$uri->isAbsolute()) {
         $uri = UriResolver::resolve($source->getBaseUri(), $uri);
     }
     $request = new GetRequest($uri, array('Accept' => 'application/schema+json'));
     $response = $this->httpClient->request($request);
     if ($response->getStatusCode() == 200) {
         $schema = (string) $response->getBody();
         $data = Json::decode($schema);
         $document = new Document($data, $resolver, null, $uri);
         return $document;
     } else {
         throw new RuntimeException('Could not load external schema ' . $uri->toString() . ' received ' . $response->getStatusCode());
     }
 }
コード例 #2
0
ファイル: UriResolver.php プロジェクト: seytar/psx
 /**
  * Resolves an base uri against an target uri
  *
  * @param \PSX\Uri $baseUri
  * @param \PSX\Uri $targetUri
  * @return \PSX\Uri
  */
 public static function resolve(Uri $baseUri, Uri $targetUri)
 {
     if (!$baseUri->isAbsolute()) {
         throw new InvalidArgumentException('Base uri must be absolute');
     }
     // if the target uri is absolute
     if ($targetUri->isAbsolute()) {
         $path = $targetUri->getPath();
         if (!empty($path)) {
             return $targetUri->withPath(self::removeDotSegments($path));
         } else {
             return $targetUri;
         }
     } else {
         $authority = $targetUri->getAuthority();
         $path = $targetUri->getPath();
         $query = $targetUri->getQuery();
         if (!empty($authority)) {
             if (!empty($path)) {
                 $path = self::removeDotSegments($path);
             }
         } else {
             if (empty($path)) {
                 if (empty($query)) {
                     $path = $baseUri->getPath();
                     $query = $baseUri->getQuery();
                 } else {
                     $path = self::merge($baseUri->getPath(), '');
                 }
             } else {
                 if (substr($path, 0, 1) == '/') {
                     $path = self::removeDotSegments($path);
                 } else {
                     $path = self::merge($baseUri->getPath(), $path);
                     $path = self::removeDotSegments($path);
                 }
             }
             $authority = $baseUri->getAuthority();
         }
         return new Uri($baseUri->getScheme(), $authority, $path, $query, $targetUri->getFragment());
     }
 }