* @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:----SEShXp5HMClZIJpSoxItFGszIes9mQKVAW/yGgRd1ChkRvmrW6SWMgKJbgUV141iEZQOKR1b7hZTbR2qQBtz97ZxJWE+M4LhL/o31jSfVzGZ4FfLrXHbPJZkmrV8/QsWKSwJejFVmWvIDb55L9UNedD4+frYqyvKfDLzRBZbbFgwd1laOOVPlG8mVILF10Hov9vJsSnEztG9zzTHVkMIt82m0VwZFzLXdwJEuBfw4gfDFmaS4EC2ervcxtwAeYxXA10FdZZkz8Ovu73vawsZrRV0lR2kAK6uhpBmJSNz+/pk4c4jVouLuaS7xqn85iVBYtr+ZeWjff4H/anUkBBMWwROqyaXaX08qfPTcFYbFYtO70MqLwXw8YaNZ13JuuvvI1sp5YxfdpWX+d1mTPKmVQOBFThb/CRcxaQ7c/hdEG7bw//Q8zkvRh5c+VznLn5TQAV5pQYPqQStXiIr/7OUhP6BcMheViUZZH5JOdW5VSILe3Fylqq+UuoFQd70LOX9CDModZgRjy5CKC2GojBfwQSdIGTAjEI90SjyKmDc8YJ7sGS0axUij7XV8hSJfrE/wTHi9Eu2joOFJY0aDRXz9YTYUQaWd7e3vbG8mojXglNl5UIJgdkkIMxzoag86RsFFL+X13EIQHQdaqcGSmkgXpCkVpsCv+bXAw27HK9N0aI=----ATTACHMENT:----MTI2MTg4NDQ5MjE5Nzc3OCA3NzU0MTkwMzQ1MDI2NTUgODExNDE1NTIzNDAwNjQ=