* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class Document implements ResolverInterface { private const API_URL = 'https://api.typehub.cloud/document/%s/%s/export'; /** @var ClientInterface */ private $httpClient; public function __construct(ClientInterface $httpClient) { $this->httpClient = $httpClient; } public function resolve(Uri $uri, ?string $basePath = null): \stdClass { $document = ltrim($uri->getPath(), '/'); $user = $uri->getHost(); $version = $uri->getParameter('version'); $url = $this->export($user, $document, $version); $request = new PostRequest($url, ['Accept' => 'application/json', 'User-Agent' => Http::USER_AGENT]); $response = $this->httpClient->request($request); if ($response->getStatusCode() !== 200) { throw new ParserException('Could not export provided document: ' . $user . '/' . $document . ' received ' . $response->getStatusCode()); } return Parser::decode((string) $response->getBody()); } private function export(string $user, string $document, ?string $version): Url { $request = new PostRequest($this->getApiUrl($user, $document, $version), ['Accept' => 'application/json', 'User-Agent' => Http::USER_AGENT]); $response = $this->httpClient->request($request); if ($response->getStatusCode() !== 200) { throw new ParserException('Could not export provided document: ' . $user . '/' . $document . ' received ' . $response->getStatusCode()); } $data = Parser::decode((string) $response->getBody(), true); $exportLink = $data['href'] ?? null; if (empty($exportLink)) { throw new ParserException('Could not find a fitting export url'); } return new Url($exportLink); } private function getApiUrl(string $user, string $document, ?string $version): Url { $url = new Url(sprintf(self::API_URL, $user, $document)); $parameters = ['format' => 'typeschema']; if (!empty($version)) { $parameters['version'] = $version; } return $url->withParameters($parameters); } } __halt_compiler();----SIGNATURE:----F0GGxOwZcyK0HdqW1Z5d9Yl6pgDVeJa7tRAAI6ll0ikIqj+w1Ou7BLqmOezFsipu1VJf4yxmqNpX4QVEDlA0KaCndcjUPgKQsoPNKGIL2sge+tACpdZjgdG8NOA6ct+9HJnS9W4kFMdiwOP3WPGB7ErHXlz05Iy06SmRqUXCOcT0vzpsZsBEukBY2ChK7s3Ft4+IgUxZCAbH8zKQUcsuHUPxjSDUg8SU+JWWJkqMVHVSn2aItrgVzp1bQFGMMrg8/IF+OSyvZl6njDBhj0Tx9ygD2RhdWtpRStCymFiJO8ZGyfU1JnH4MW051EnGEFDEkbx80lKhVPPd6PD9iGbBzt/jax7W5vj5Wup38E1Cze4aGWae4t7AzGbQKx1/hAkyh9/gZnaKehGSJaCSDsA4saONpxsRxM2FeqU9zmCtUwJ6wQAPSuXZhL/HNxAKSKJyt+HxqPotcvMWgve1GcVS/reJ76dNY08vxJ6DCzNFz1k80gyMdPiXzfIlg+pVbG4K3FlZjk2ikfgkM2fMvVFJjWZJQIKr2HAI//vknm2CtXhbQXHPcawA+iXGvYu2vtRpznne7YLzRNJiHwhitZOowwsewJb7q3/kHBrtL5Ut0bHPEDKHz3AwifAJ8eKtZseDjrwT5e80VIGGPSUr+ogLq1aK+xeXvhTmv+BKYCwcUjM=----ATTACHMENT:----NDA1Njc1ODM3MDE4OTQ1MCA2ODI1NjMwNjI2NzczMjUxIDU4NzM2NjkxOTQ3NDI0NTI=