Add a basic PHP server-generator example

This commit is contained in:
Laurent Sarrazin
2014-10-30 22:13:27 +01:00
parent 88692ec42d
commit 06332e5dce
10 changed files with 264 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>

View File

@@ -0,0 +1,10 @@
# Swagger generated server
## Overview
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the
[swagger-spec](https://github.com/swagger-api/swagger-core/wiki) from a remote server, you can easily generate a server stub. This
is an example of building a PHP server.
This example uses the [Silex](http://silex.sensiolabs.org/) micro-framework. To see how to make this your own, look here:
[README](https://github.com/swagger-api/swagger-codegen/tree/master/samples/server-generator/php)

View File

@@ -0,0 +1,5 @@
{
"require": {
"silex/silex": "~1.2"
}
}

View File

@@ -0,0 +1,26 @@
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Silex\Application;
$app = new Silex\Application();
{{#apiInfo}}
{{#apis}}
{{#operations}}
{{#operation}}
$app->{{httpMethod}}('{{path}}', function(Application $app, Request $request{{#pathParams}}, ${{paramName}}{{/pathParams}}) {
{{#queryParams}}${{paramName}} = $request->get('{{paramName}}');{{newline}} {{/queryParams}}
{{#formParams}}${{paramName}} = $request->get('{{paramName}}');{{newline}} {{/formParams}}
return new Response('How about implementing {{nickname}} as a {{httpMethod}} method ?');
});
{{/operation}}
{{/operations}}
{{/apis}}
{{/apiInfo}}
$app->run();