php-slim4-server.api.mustache Maven / Gradle / Ivy
container = $container;
}
{{#operations}}
{{#operation}}
/**
* {{httpMethod}} {{operationId}}
{{#summary}}
* Summary: {{summary}}
{{/summary}}
{{#notes}}
* Notes: {{notes}}
{{/notes}}
{{#hasProduces}}
* Output-Formats: [{{#produces}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/produces}}]
{{/hasProduces}}
*
* @param ServerRequestInterface $request Request
* @param ResponseInterface $response Response
* @param array|null $args Path arguments
*
* @return ResponseInterface
* @throws Exception to force implementation class to override this method
*/
public function {{operationId}}(ServerRequestInterface $request, ResponseInterface $response, array $args)
{
{{#hasHeaderParams}}
$headers = $request->getHeaders();
{{#headerParams}}
${{paramName}} = $request->hasHeader('{{baseName}}') ? $headers['{{baseName}}'] : null;
{{/headerParams}}
{{/hasHeaderParams}}
{{#hasPathParams}}
{{#pathParams}}
${{paramName}} = $args['{{baseName}}'];
{{/pathParams}}
{{/hasPathParams}}
{{#hasQueryParams}}
$queryParams = $request->getQueryParams();
{{#queryParams}}
${{paramName}} = (key_exists('{{baseName}}', $queryParams)) ? $queryParams['{{baseName}}'] : null;
{{/queryParams}}
{{/hasQueryParams}}
{{#hasFormParams}}
$body = $request->getParsedBody();
{{#formParams}}
{{^isFile}}
${{paramName}} = (isset($body['{{baseName}}'])) ? $body['{{baseName}}'] : null;
{{/isFile}}
{{#isFile}}
{{#isMultipart}}
${{paramName}} = (key_exists('{{baseName}}', $request->getUploadedFiles())) ? $request->getUploadedFiles()['{{baseName}}'] : null;
{{/isMultipart}}
{{^isMultipart}}
${{paramName}} = (isset($body['{{baseName}}'])) ? $body['{{baseName}}'] : null;
{{/isMultipart}}
{{/isFile}}
{{/formParams}}
{{/hasFormParams}}
{{#hasBodyParam}}
$body = $request->getParsedBody();
{{/hasBodyParam}}
$message = "How about implementing {{nickname}} as a {{httpMethod}} method in {{apiPackage}}\{{userClassname}} class?";
throw new Exception($message);
$response->getBody()->write($message);
return $response->withStatus(501);
}
{{/operation}}
{{/operations}}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy