예제 #1
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());
     }
 }
예제 #2
0
파일: Resolver.php 프로젝트: uqiauto/fusio
 public function resolve(Uri $uri, Document $source, RefResolver $resolver)
 {
     $name = ltrim($uri->getPath(), '/');
     $row = $this->connection->fetchAssoc('SELECT name, source FROM fusio_schema WHERE name LIKE :name', array('name' => $name));
     if (!empty($row)) {
         $data = Json::decode($row['source']);
         if (is_array($data)) {
             $document = new Document($data, $resolver, null, $uri);
             return $document;
         } else {
             throw new RuntimeException(sprintf('Schema %s must be an object', $row['name']));
         }
     } else {
         throw new RuntimeException('Invalid schema reference ' . $name);
     }
 }
예제 #3
0
파일: File.php 프로젝트: seytar/psx
 public function resolve(Uri $uri, Document $source, RefResolver $resolver)
 {
     if ($source->isRemote()) {
         throw new RuntimeException('Can not resolve file scheme from remote source');
     }
     $path = str_replace('/', DIRECTORY_SEPARATOR, ltrim($uri->getPath(), '/'));
     $path = $source->getBasePath() !== null ? $source->getBasePath() . DIRECTORY_SEPARATOR . $path : $path;
     if (is_file($path)) {
         $basePath = pathinfo($path, PATHINFO_DIRNAME);
         $schema = file_get_contents($path);
         $data = Json::decode($schema);
         $document = new Document($data, $resolver, $basePath, $uri);
         return $document;
     } else {
         throw new RuntimeException('Could not load external schema ' . $path);
     }
 }
예제 #4
0
파일: Document.php 프로젝트: seytar/psx
 /**
  * @param \PSX\Uri $ref
  * @return boolean
  */
 public function canResolve(Uri $ref)
 {
     return $this->baseUri->getHost() == $ref->getHost() && $this->baseUri->getPath() == $ref->getPath();
 }
예제 #5
0
파일: RefResolver.php 프로젝트: seytar/psx
 protected function getKey(Uri $uri)
 {
     return $uri->getScheme() . '-' . $uri->getHost() . '-' . $uri->getPath();
 }