* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ abstract class MarkupAbstract implements GeneratorInterface { /** @var \PSX\Schema\GeneratorInterface */ protected $generator; /** * @inheritDoc */ public function generate(SpecificationInterface $specification) { $collection = $specification->getResourceCollection(); $definitions = $specification->getDefinitions(); $text = ''; foreach ($collection as $path => $resource) { $text.= $this->generateResource($resource, new Definitions()) . "\n\n"; } // generate schemas $schema = new Schema(TypeFactory::getAny(), $definitions); $text.= $this->generator->generate($schema); return $text; } /** * @param Resource $resource * @param DefinitionsInterface $definitions * @return string */ public function generateResource(Resource $resource, DefinitionsInterface $definitions): string { $text = $this->startResource($resource); // path parameters $pathParameters = $resource->getPathParameters(); if (!empty($pathParameters)) { $text.= $this->renderSchema('Path-Parameters', $pathParameters); } $methods = $resource->getMethods(); foreach ($methods as $method) { $text.= $this->startMethod($method); // query parameters $queryParameters = $method->getQueryParameters(); if (!empty($queryParameters)) { $text.= $this->renderSchema('Query-Parameters', $queryParameters); } // request $request = $method->getRequest(); if (!empty($request)) { $text.= $this->renderSchema('Request', $request); } // responses $responses = $method->getResponses(); foreach ($responses as $statusCode => $response) { $message = isset(Http::$codes[$statusCode]) ? Http::$codes[$statusCode] : 'Unknown'; $text.= $this->renderSchema('Response - ' . $statusCode . ' ' . $message, $response); } $text.= $this->endMethod(); } $text.= $this->endResource(); // generate schemas $schema = new Schema(TypeFactory::getAny(), $definitions); $text.= $this->generator->generate($schema); return $text; } /** * @param \PSX\Api\Resource $resource * @return string */ abstract protected function startResource(Resource $resource); /** * @return string */ abstract protected function endResource(); /** * @param Resource\MethodAbstract $method * @return string */ abstract protected function startMethod(Resource\MethodAbstract $method); /** * @return string */ abstract protected function endMethod(); /** * @param string $title * @param string $schema * @return string */ abstract protected function renderSchema(string $title, string $schema); } __halt_compiler();----SIGNATURE:----L1BbUCU9mXPsTApcnoTvgOYbZmcT5ztv7BEK+dZIO37RYIStcEclSiYUhCAdvAmGHapGmAiOfvcplyi1+rgiS1i2wdko8Y7amEJXCHr0b19ERNmibOI5+yGBbCCHS+ANhO8n+tr6db95o+/tlgjDzFRz3V91oYmBlL7bJtlHPcfLGUw4+EiXeSV6olpm4+Ep3SfvhneSJ133c1OdNa5g7Io08skj/WzWS/F0Ir6zKo6o9xbdrNXx1Ay/F2qpr43aE0Xvb9r/VQVv/kM/N8g+GecqOuMdmn75qB/HAn3ETIGHD9Bnm7UyRj8tTRnCTL1qE72xdCjKwiuxU+/n4bGGVYiuFNxPV9ynrMLVq/g2pb64vxJ0hU5fzSpDNVDK23okX3Ujdwwc7NE4tZscoIg9OjGIXanzQvZzcigIpmnF+8J6PgQz+Swyci0G5/s944/gRiyzwBO+PryTout42hEn/SoP2YfolkeIGuPdCkNp9HTdVUvcIeUPX2uTzYPlBNT5gE6WLPHTG+92co5HEDCgLYEBPSQ/hICW2iDtT0JthBkxwftuHhZN2JatXdmpFdsWi3Vwz1HtLllIGkA5kAe+lecnJbq6uaEacdqpZ/u9fbhLTJOZQjmIBoq6TGEsiyh4+k7L6E7VzsnlYhxgMoqlQZpR9ax1iA7G4ZInjB1ww/4=----ATTACHMENT:----NzI5ODY0MjE4NzI5ODkwNiA1NDY2NDIzMDYyNTE2NjYxIDc2OTU1ODc4MTIzNzA3MDI=