public function onGet() { parent::onGet(); $version = $this->getUriFragment('version'); $path = $this->getUriFragment('path'); $doc = $this->resourceListing->getDocumentation($path); if ($doc instanceof DocumentationInterface) { if ($version == '*') { $version = $doc->getLatestVersion(); } $resource = $doc->getResource($version); if (!$resource instanceof Resource) { throw new HttpException\NotFoundException('Given version is not available'); } $path = ltrim($resource->getPath(), '/'); $title = $resource->getTitle(); if (empty($title)) { $title = ApiGeneration::generateTitleFromRoute($path); } $endpoint = $this->config['psx_url'] . '/' . $this->config['psx_dispatch'] . $path; $targetNamespace = $this->config['psx_soap_namespace']; $this->response->setHeader('Content-Type', 'text/xml'); $generator = new Generator\Wsdl($title, $endpoint, $targetNamespace); $this->setBody($generator->generate($resource)); } else { throw new HttpException\NotFoundException('Invalid resource'); } }
public function onGet() { parent::onGet(); $version = $this->getUriFragment('version'); $path = $this->getUriFragment('path'); $doc = $this->resourceListing->getDocumentation($path); if ($doc instanceof DocumentationInterface) { if ($version == '*') { $version = $doc->getLatestVersion(); } $resource = $doc->getResource($version); if (!$resource instanceof Resource) { throw new HttpException\NotFoundException('Given version is not available'); } $path = ltrim($resource->getPath(), '/'); $title = $resource->getTitle(); if (empty($title)) { $title = str_replace(' ', '', ucwords(str_replace('/', ' ', $path))); } $baseUri = $this->config['psx_url'] . '/' . $this->config['psx_dispatch']; $targetNamespace = $this->config['psx_json_namespace']; $this->response->setHeader('Content-Type', 'application/raml+yaml'); $generator = new Generator\Raml($title, $version, $baseUri, $targetNamespace); $this->setBody($generator->generate($resource)); } else { throw new HttpException\NotFoundException('Invalid resource'); } }
public function onLoad() { parent::onLoad(); $doc = $this->resourceListing->getDocumentation($this->context->get(Context::KEY_PATH)); if (!$doc instanceof DocumentationInterface) { throw new RuntimeException('No documentation available'); } $this->version = $this->getVersion($doc); $this->resource = $this->getResource($doc, $this->version); if (!$this->resource->hasMethod($this->getMethod())) { throw new StatusCode\MethodNotAllowedException('Method is not allowed', $this->resource->getAllowedMethods()); } $this->pathParameters = $this->schemaAssimilator->assimilate($this->resource->getPathParameters(), $this->uriFragments); $this->queryParameters = $this->schemaAssimilator->assimilate($this->resource->getMethod($this->getMethod())->getQueryParameters(), $this->request->getUri()->getParameters()); }
public function doDetail() { $version = $this->getUriFragment('version'); $path = $this->getUriFragment('path'); $doc = $this->resourceListing->getDocumentation($path); if ($doc instanceof DocumentationInterface) { if ($version == '*') { $version = $doc->getLatestVersion(); } $resource = $doc->getResource($version); if (!$resource instanceof Resource) { throw new HttpException\NotFoundException('Given version is not available'); } $baseUri = $this->config['psx_url'] . '/' . $this->config['psx_dispatch']; $targetNamespace = $this->config['psx_json_namespace']; $this->response->setHeader('Content-Type', 'application/json'); $generator = new Generator\Swagger($version, $baseUri, $targetNamespace); $this->setBody($generator->generate($resource)); } else { throw new HttpException\NotFoundException('Invalid resource'); } }
public function doDetail() { $version = $this->getUriFragment('version'); $path = $this->getUriFragment('path') ?: '/'; if (empty($version) || empty($path)) { throw new HttpException\BadRequestException('Version and path not provided'); } $documentation = $this->resourceListing->getDocumentation($path); if (!$documentation instanceof DocumentationInterface) { throw new HttpException\InternalServerErrorException('Controller provides no documentation informations'); } if ($version == '*') { $version = $documentation->getLatestVersion(); $resource = $documentation->getResource($version); } else { $resource = $documentation->getResource($version); } if ($resource instanceof Resource) { $resources = $documentation->getResources(); krsort($resources); $versions = array(); foreach ($resources as $key => $row) { $versions[] = new Record('version', ['version' => $key, 'status' => $row->getStatus()]); } $generators = $this->getViewGenerators(); $data = array(); foreach ($generators as $name => $generator) { if ($generator instanceof HtmlAbstract) { $data[$generator->getName()] = $generator->generate($resource); } } $this->setBody(array('method' => $resource->getAllowedMethods(), 'path' => $resource->getPath(), 'description' => $resource->getDescription(), 'versions' => $versions, 'see_others' => $this->getSeeOthers($version, $resource->getPath()), 'resource' => new Record('resource', ['version' => $version, 'status' => $resource->getStatus(), 'data' => new Record('data', $data)]))); } else { throw new HttpException\BadRequestException('Invalid api version'); } }