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); } }
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()); } }
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); } }
protected function parse($urn) { // URNs are case insensitive $urn = strtolower((string) $urn); parent::parse($urn); // must have an urn scheme and path part if ($this->scheme != 'urn' || empty($this->path)) { throw new InvalidArgumentException('Invalid urn syntax'); } // parse $this->nid = strstr($this->path, ':', true); $this->nss = substr(strstr($this->path, ':'), 1); }
/** * 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()); } }
protected function parse($url) { $url = (string) $url; // append http scheme for urls starting with //. Normally // means that // we use the scheme from the base url but in this context there is no // base url available so we assume http if (substr($url, 0, 2) == '//') { $url = 'http:' . $url; } parent::parse($url); // we need at least an scheme and host if (empty($this->scheme) || empty($this->host)) { throw new InvalidArgumentException('Invalid url syntax'); } // check port if available if ($this->port !== null) { if ($this->port < 1 || $this->port > 0xffff) { throw new InvalidArgumentException('Invalid port range'); } } }
/** * @param \PSX\Uri $ref * @return boolean */ public function canResolve(Uri $ref) { return $this->baseUri->getHost() == $ref->getHost() && $this->baseUri->getPath() == $ref->getPath(); }
protected function getKey(Uri $uri) { return $uri->getScheme() . '-' . $uri->getHost() . '-' . $uri->getPath(); }