[PHP-Lumen] Lumen 5.6 support (#212)

* Lumen 5.6 support

* recall headlines

* Update composer.mustache

* regenerate lumne php petstore samples

* remove output format from lumen routes

* Fix: "A facade root has not been set"

* Ignore log folder
This commit is contained in:
William Cheng 2018-06-16 19:07:13 +08:00 committed by GitHub
parent b1921ce484
commit 05f177b6d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
51 changed files with 875 additions and 91 deletions

View File

@ -99,18 +99,37 @@ public class PhpLumenServerCodegen extends AbstractPhpCodegen {
* entire object tree available. If the input file has a suffix of `.mustache * entire object tree available. If the input file has a suffix of `.mustache
* it will be processed by the template engine. Otherwise, it will be copied * it will be processed by the template engine. Otherwise, it will be copied
*/ */
supportingFiles.add(new SupportingFile(".env.example", packagePath + File.separator + srcBasePath, ".env.example"));
supportingFiles.add(new SupportingFile("storage_logs_.gitignore", packagePath + File.separator + srcBasePath + File.separator + "storage" + File.separator + "logs", ".gitignore"));
supportingFiles.add(new SupportingFile("artisan", packagePath + File.separator + srcBasePath, "artisan"));
supportingFiles.add(new SupportingFile("composer.mustache", packagePath + File.separator + srcBasePath, "composer.json")); supportingFiles.add(new SupportingFile("composer.mustache", packagePath + File.separator + srcBasePath, "composer.json"));
supportingFiles.add(new SupportingFile("readme.md", packagePath + File.separator + srcBasePath, "readme.md")); supportingFiles.add(new SupportingFile("readme.md", packagePath + File.separator + srcBasePath, "readme.md"));
supportingFiles.add(new SupportingFile("app.php", packagePath + File.separator + srcBasePath + File.separator + "bootstrap", "app.php"));
supportingFiles.add(new SupportingFile("index.php", packagePath + File.separator + srcBasePath + File.separator + "public", "index.php"));
supportingFiles.add(new SupportingFile("User.php", packagePath + File.separator + srcBasePath + File.separator + "app", "User.php")); supportingFiles.add(new SupportingFile("User.php", packagePath + File.separator + srcBasePath + File.separator + "app", "User.php"));
supportingFiles.add(new SupportingFile("Kernel.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Console", "Kernel.php")); supportingFiles.add(new SupportingFile("Kernel.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Console", "Kernel.php"));
supportingFiles.add(new SupportingFile(".gitkeep", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Console" + File.separator + "Commands", ".gitkeep"));
supportingFiles.add(new SupportingFile("Event.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Events", "Event.php"));
supportingFiles.add(new SupportingFile("ExampleEvent.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Events", "ExampleEvent.php"));
supportingFiles.add(new SupportingFile("Handler.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Exceptions", "Handler.php")); supportingFiles.add(new SupportingFile("Handler.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Exceptions", "Handler.php"));
supportingFiles.add(new SupportingFile("routes.mustache", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Http", "routes.php"));
supportingFiles.add(new SupportingFile("Controller.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Http" + File.separator + "Controllers" + File.separator, "Controller.php")); supportingFiles.add(new SupportingFile("Controller.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Http" + File.separator + "Controllers" + File.separator, "Controller.php"));
supportingFiles.add(new SupportingFile("ExampleController.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Http" + File.separator + "Controllers" + File.separator, "ExampleController.php"));
supportingFiles.add(new SupportingFile("Authenticate.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Http" + File.separator + "Middleware" + File.separator, "Authenticate.php")); supportingFiles.add(new SupportingFile("Authenticate.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Http" + File.separator + "Middleware" + File.separator, "Authenticate.php"));
supportingFiles.add(new SupportingFile("ExampleMiddleware.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Http" + File.separator + "Middleware" + File.separator, "ExampleMiddleware.php"));
supportingFiles.add(new SupportingFile("ExampleJob.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Jobs", "ExampleJob.php"));
supportingFiles.add(new SupportingFile("Job.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Jobs", "Job.php"));
supportingFiles.add(new SupportingFile("ExampleListener.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Listeners", "ExampleListener.php"));
supportingFiles.add(new SupportingFile("AppServiceProvider.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Providers", "AppServiceProvider.php"));
supportingFiles.add(new SupportingFile("AuthServiceProvider.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Providers", "AuthServiceProvider.php"));
supportingFiles.add(new SupportingFile("EventServiceProvider.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Providers", "EventServiceProvider.php"));
supportingFiles.add(new SupportingFile("app.php", packagePath + File.separator + srcBasePath + File.separator + "bootstrap", "app.php"));
supportingFiles.add(new SupportingFile("ModelFactory.php", packagePath + File.separator + srcBasePath + File.separator + "database" + File.separator + "factories", "ModelFactory.php"));
supportingFiles.add(new SupportingFile(".gitkeep", packagePath + File.separator + srcBasePath + File.separator + "database" + File.separator + "migrations", ".gitkeep"));
supportingFiles.add(new SupportingFile("DatabaseSeeder.php", packagePath + File.separator + srcBasePath + File.separator + "database" + File.separator + "seeds", "DatabaseSeeder.php"));
supportingFiles.add(new SupportingFile(".htaccess", packagePath + File.separator + srcBasePath + File.separator + "public", ".htaccess"));
supportingFiles.add(new SupportingFile("index.php", packagePath + File.separator + srcBasePath + File.separator + "public", "index.php"));
supportingFiles.add(new SupportingFile(".gitkeep", packagePath + File.separator + srcBasePath + File.separator + "resources" + File.separator + "views", ".gitkeep"));
supportingFiles.add(new SupportingFile("routes.mustache", packagePath + File.separator + srcBasePath + File.separator + "routes", "web.php"));
supportingFiles.add(new SupportingFile("ExampleTest.php", packagePath + File.separator + srcBasePath + File.separator + "tests", "ExampleTest.php"));
supportingFiles.add(new SupportingFile("TestCase.php", packagePath + File.separator + srcBasePath + File.separator + "tests", "TestCase.php"));
} }
// override with any special post-processing // override with any special post-processing

View File

@ -0,0 +1,17 @@
APP_ENV=local
APP_DEBUG=true
APP_KEY=
APP_TIMEZONE=UTC
LOG_CHANNEL=stack
LOG_SLACK_WEBHOOK_URL=
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
CACHE_DRIVER=file
QUEUE_DRIVER=sync

View File

@ -0,0 +1,21 @@
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

View File

@ -0,0 +1,18 @@
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace App\Providers;
use App\User;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Boot the authentication services for the application.
*
* @return void
*/
public function boot()
{
// Here you may define how you wish users to be authenticated for your Lumen
// application. The callback which receives the incoming request instance
// should return either a User instance or null. You're free to obtain
// the User instance via an API token or any other method necessary.
$this->app['auth']->viaRequest('api', function ($request) {
if ($request->input('api_token')) {
return User::where('api_token', $request->input('api_token'))->first();
}
});
}
}

View File

@ -1,6 +1,6 @@
<?php <?php
/** /*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech * https://openapi-generator.tech
* Do not edit the class manually. * Do not edit the class manually.

View File

@ -0,0 +1,16 @@
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
// $this->call('UsersTableSeeder');
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace App\Events;
use Illuminate\Queue\SerializesModels;
abstract class Event
{
use SerializesModels;
}

View File

@ -0,0 +1,19 @@
<?php
namespace App\Providers;
use Laravel\Lumen\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
'App\Events\ExampleEvent' => [
'App\Listeners\ExampleListener',
],
];
}

View File

@ -0,0 +1,18 @@
<?php
namespace App\Http\Controllers;
class ExampleController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
//
}
//
}

View File

@ -0,0 +1,16 @@
<?php
namespace App\Events;
class ExampleEvent extends Event
{
/**
* Create a new event instance.
*
* @return void
*/
public function __construct()
{
//
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\Jobs;
class ExampleJob extends Job
{
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace App\Listeners;
use App\Events\ExampleEvent;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class ExampleListener
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param ExampleEvent $event
* @return void
*/
public function handle(ExampleEvent $event)
{
//
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace App\Http\Middleware;
use Closure;
class ExampleMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
return $next($request);
}
}

View File

@ -0,0 +1,21 @@
<?php
use Laravel\Lumen\Testing\DatabaseMigrations;
use Laravel\Lumen\Testing\DatabaseTransactions;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testExample()
{
$this->get('/');
$this->assertEquals(
$this->app->version(), $this->response->getContent()
);
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
abstract class Job implements ShouldQueue
{
/*
|--------------------------------------------------------------------------
| Queueable Jobs
|--------------------------------------------------------------------------
|
| This job base class provides a central location to place any logic that
| is shared across all of your jobs. The trait included with the class
| provides access to the "queueOn" and "delay" queue helper methods.
|
*/
use InteractsWithQueue, Queueable, SerializesModels;
}

View File

@ -0,0 +1,19 @@
<?php
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
$factory->define(App\User::class, function (Faker\Generator $faker) {
return [
'name' => $faker->name,
'email' => $faker->email,
];
});

View File

@ -0,0 +1,14 @@
<?php
abstract class TestCase extends Laravel\Lumen\Testing\TestCase
{
/**
* Creates the application.
*
* @return \Laravel\Lumen\Application
*/
public function createApplication()
{
return require __DIR__.'/../bootstrap/app.php';
}
}

View File

@ -29,7 +29,7 @@ $app = new Laravel\Lumen\Application(
realpath(__DIR__.'/../') realpath(__DIR__.'/../')
); );
$app->withFacades(); // $app->withFacades();
// $app->withEloquent(); // $app->withEloquent();
@ -99,8 +99,12 @@ $app->singleton(
| |
*/ */
$app->group(['namespace' => 'App\Http\Controllers'], function ($app) { $app->router->group([
require __DIR__.'/../app/Http/routes.php'; 'namespace' => 'App\Http\Controllers',
], function ($router) {
require __DIR__.'/../routes/web.php';
}); });
$app->withFacades();
return $app; return $app;

View File

@ -5,6 +5,9 @@
{{/artifactVersion}} {{/artifactVersion}}
"description": "{{description}}", "description": "{{description}}",
"keywords": [ "keywords": [
"framework",
"laravel",
"lumen",
"openapi", "openapi",
"openapitools", "openapitools",
"php", "php",
@ -19,14 +22,38 @@
"homepage": "https://openapi-generator.tech" "homepage": "https://openapi-generator.tech"
} }
], ],
"type": "project",
"require": { "require": {
"php": ">=5.5.9", "php": ">=7.1.3",
"laravel/lumen-framework": "5.2.*", "laravel/lumen-framework": "5.6.*",
"vlucas/phpdotenv": "~2.2" "vlucas/phpdotenv": "~2.2"
}, },
"require-dev": {
"fzaninotto/faker": "~1.4",
"phpunit/phpunit": "~7.0",
"mockery/mockery": "~1.0"
},
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"App\\": "app/" "App\\": "app/"
} }
} },
"autoload-dev": {
"classmap": [
"tests/",
"database/"
]
},
"scripts": {
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
},
"minimum-stability": "dev",
"prefer-stable": true
} }

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="bootstrap/app.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
</php>
</phpunit>

View File

@ -12,5 +12,11 @@ This example uses the [Lumen Framework](http://lumen.laravel.com/). To see how
## Installation & Usage ## Installation & Usage
### Composer ### Composer
Using `composer install` to install the framework and dependencies via [Composer](http://getcomposer.org/). Switch to the generated Lumen server stub directory.
Using `composer update` to install the framework and dependencies via [Composer](http://getcomposer.org/).
## Note
The `composer update` should be the first thing to do right after generating Lumen server stub. The autoload.php will be generated only after excuting `composer update`.
Or there would be errors during service or model migration.

View File

@ -6,8 +6,8 @@
* @version {{appVersion}} * @version {{appVersion}}
*/ */
$app->get('/', function () use ($app) { $router->get('/', function () use ($router) {
return $app->version(); return $router->app->version();
}); });
{{#apis}} {{#apis}}
@ -17,9 +17,8 @@ $app->get('/', function () use ($app) {
* {{httpMethod}} {{operationId}} * {{httpMethod}} {{operationId}}
* Summary: {{summary}} * Summary: {{summary}}
* Notes: {{notes}} * Notes: {{notes}}
{{#hasProduces}} * Output-Formats: [{{#produces}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/produces}}]{{/hasProduces}}
*/ */
$app->{{httpMethod}}('{{{basePathWithoutHost}}}{{{path}}}', '{{classname}}@{{operationId}}'); $router->{{httpMethod}}('{{{basePathWithoutHost}}}{{{path}}}', '{{classname}}@{{operationId}}');
{{/operation}} {{/operation}}
{{/operations}} {{/operations}}
{{/apis}} {{/apis}}

View File

@ -0,0 +1,2 @@
*
!.gitignore

View File

@ -0,0 +1,17 @@
APP_ENV=local
APP_DEBUG=true
APP_KEY=
APP_TIMEZONE=UTC
LOG_CHANNEL=stack
LOG_SLACK_WEBHOOK_URL=
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
CACHE_DRIVER=file
QUEUE_DRIVER=sync

View File

@ -0,0 +1,10 @@
<?php
namespace App\Events;
use Illuminate\Queue\SerializesModels;
abstract class Event
{
use SerializesModels;
}

View File

@ -0,0 +1,16 @@
<?php
namespace App\Events;
class ExampleEvent extends Event
{
/**
* Create a new event instance.
*
* @return void
*/
public function __construct()
{
//
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace App\Http\Controllers;
class ExampleController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
//
}
//
}

View File

@ -1,6 +1,6 @@
<?php <?php
/** /*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech * https://openapi-generator.tech
* Do not edit the class manually. * Do not edit the class manually.

View File

@ -0,0 +1,20 @@
<?php
namespace App\Http\Middleware;
use Closure;
class ExampleMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
return $next($request);
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\Jobs;
class ExampleJob extends Job
{
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
abstract class Job implements ShouldQueue
{
/*
|--------------------------------------------------------------------------
| Queueable Jobs
|--------------------------------------------------------------------------
|
| This job base class provides a central location to place any logic that
| is shared across all of your jobs. The trait included with the class
| provides access to the "queueOn" and "delay" queue helper methods.
|
*/
use InteractsWithQueue, Queueable, SerializesModels;
}

View File

@ -0,0 +1,31 @@
<?php
namespace App\Listeners;
use App\Events\ExampleEvent;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class ExampleListener
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param ExampleEvent $event
* @return void
*/
public function handle(ExampleEvent $event)
{
//
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace App\Providers;
use App\User;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Boot the authentication services for the application.
*
* @return void
*/
public function boot()
{
// Here you may define how you wish users to be authenticated for your Lumen
// application. The callback which receives the incoming request instance
// should return either a User instance or null. You're free to obtain
// the User instance via an API token or any other method necessary.
$this->app['auth']->viaRequest('api', function ($request) {
if ($request->input('api_token')) {
return User::where('api_token', $request->input('api_token'))->first();
}
});
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace App\Providers;
use Laravel\Lumen\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
'App\Events\ExampleEvent' => [
'App\Listeners\ExampleListener',
],
];
}

View File

@ -0,0 +1,35 @@
#!/usr/bin/env php
<?php
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;
/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| First we need to get an application instance. This creates an instance
| of the application / container and bootstraps the application so it
| is ready to receive HTTP / Console requests from the environment.
|
*/
$app = require __DIR__.'/bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Artisan Application
|--------------------------------------------------------------------------
|
| When we run the console application, the current CLI command will be
| executed in this console and the response sent back to a terminal
| or another output device for the developers. Here goes nothing!
|
*/
$kernel = $app->make(
'Illuminate\Contracts\Console\Kernel'
);
exit($kernel->handle(new ArgvInput, new ConsoleOutput));

View File

@ -29,7 +29,7 @@ $app = new Laravel\Lumen\Application(
realpath(__DIR__.'/../') realpath(__DIR__.'/../')
); );
$app->withFacades(); // $app->withFacades();
// $app->withEloquent(); // $app->withEloquent();
@ -99,8 +99,12 @@ $app->singleton(
| |
*/ */
$app->group(['namespace' => 'App\Http\Controllers'], function ($app) { $app->router->group([
require __DIR__.'/../app/Http/routes.php'; 'namespace' => 'App\Http\Controllers',
], function ($router) {
require __DIR__.'/../routes/web.php';
}); });
$app->withFacades();
return $app; return $app;

View File

@ -2,6 +2,9 @@
"name": "GIT_USER_ID/GIT_REPO_ID", "name": "GIT_USER_ID/GIT_REPO_ID",
"description": "", "description": "",
"keywords": [ "keywords": [
"framework",
"laravel",
"lumen",
"openapi", "openapi",
"openapitools", "openapitools",
"php", "php",
@ -16,14 +19,38 @@
"homepage": "https://openapi-generator.tech" "homepage": "https://openapi-generator.tech"
} }
], ],
"type": "project",
"require": { "require": {
"php": ">=5.5.9", "php": ">=7.1.3",
"laravel/lumen-framework": "5.2.*", "laravel/lumen-framework": "5.6.*",
"vlucas/phpdotenv": "~2.2" "vlucas/phpdotenv": "~2.2"
}, },
"require-dev": {
"fzaninotto/faker": "~1.4",
"phpunit/phpunit": "~7.0",
"mockery/mockery": "~1.0"
},
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"App\\": "app/" "App\\": "app/"
} }
} },
"autoload-dev": {
"classmap": [
"tests/",
"database/"
]
},
"scripts": {
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
},
"minimum-stability": "dev",
"prefer-stable": true
} }

View File

@ -0,0 +1,19 @@
<?php
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
$factory->define(App\User::class, function (Faker\Generator $faker) {
return [
'name' => $faker->name,
'email' => $faker->email,
];
});

View File

@ -0,0 +1,16 @@
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
// $this->call('UsersTableSeeder');
}
}

View File

@ -0,0 +1,21 @@
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

View File

@ -12,5 +12,11 @@ This example uses the [Lumen Framework](http://lumen.laravel.com/). To see how
## Installation & Usage ## Installation & Usage
### Composer ### Composer
Using `composer install` to install the framework and dependencies via [Composer](http://getcomposer.org/). Switch to the generated Lumen server stub directory.
Using `composer update` to install the framework and dependencies via [Composer](http://getcomposer.org/).
## Note
The `composer update` should be the first thing to do right after generating Lumen server stub. The autoload.php will be generated only after excuting `composer update`.
Or there would be errors during service or model migration.

View File

@ -17,232 +17,200 @@
* @version 1.0.0 * @version 1.0.0
*/ */
$app->get('/', function () use ($app) { $router->get('/', function () use ($router) {
return $app->version(); return $router->app->version();
}); });
/** /**
* patch testSpecialTags * patch testSpecialTags
* Summary: To test special tags * Summary: To test special tags
* Notes: To test special tags * Notes: To test special tags
* Output-Formats: [application/json]
*/ */
$app->patch('/v2/another-fake/dummy', 'AnotherFakeApi@testSpecialTags'); $router->patch('/v2/another-fake/dummy', 'AnotherFakeApi@testSpecialTags');
/** /**
* patch testClientModel * patch testClientModel
* Summary: To test \&quot;client\&quot; model * Summary: To test \&quot;client\&quot; model
* Notes: To test \&quot;client\&quot; model * Notes: To test \&quot;client\&quot; model
* Output-Formats: [application/json]
*/ */
$app->patch('/v2/fake', 'FakeApi@testClientModel'); $router->patch('/v2/fake', 'FakeApi@testClientModel');
/** /**
* post testEndpointParameters * post testEndpointParameters
* Summary: Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 * Summary: Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
* Notes: Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 * Notes: Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
*/ */
$app->post('/v2/fake', 'FakeApi@testEndpointParameters'); $router->post('/v2/fake', 'FakeApi@testEndpointParameters');
/** /**
* get testEnumParameters * get testEnumParameters
* Summary: To test enum parameters * Summary: To test enum parameters
* Notes: To test enum parameters * Notes: To test enum parameters
*/ */
$app->get('/v2/fake', 'FakeApi@testEnumParameters'); $router->get('/v2/fake', 'FakeApi@testEnumParameters');
/** /**
* put testBodyWithQueryParams * put testBodyWithQueryParams
* Summary: * Summary:
* Notes: * Notes:
*/ */
$app->put('/v2/fake/body-with-query-params', 'FakeApi@testBodyWithQueryParams'); $router->put('/v2/fake/body-with-query-params', 'FakeApi@testBodyWithQueryParams');
/** /**
* post testInlineAdditionalProperties * post testInlineAdditionalProperties
* Summary: test inline additionalProperties * Summary: test inline additionalProperties
* Notes: * Notes:
*/ */
$app->post('/v2/fake/inline-additionalProperties', 'FakeApi@testInlineAdditionalProperties'); $router->post('/v2/fake/inline-additionalProperties', 'FakeApi@testInlineAdditionalProperties');
/** /**
* get testJsonFormData * get testJsonFormData
* Summary: test json serialization of form data * Summary: test json serialization of form data
* Notes: * Notes:
*/ */
$app->get('/v2/fake/jsonFormData', 'FakeApi@testJsonFormData'); $router->get('/v2/fake/jsonFormData', 'FakeApi@testJsonFormData');
/** /**
* post fakeOuterBooleanSerialize * post fakeOuterBooleanSerialize
* Summary: * Summary:
* Notes: Test serialization of outer boolean types * Notes: Test serialization of outer boolean types
* Output-Formats: [*/*]
*/ */
$app->post('/v2/fake/outer/boolean', 'FakeApi@fakeOuterBooleanSerialize'); $router->post('/v2/fake/outer/boolean', 'FakeApi@fakeOuterBooleanSerialize');
/** /**
* post fakeOuterCompositeSerialize * post fakeOuterCompositeSerialize
* Summary: * Summary:
* Notes: Test serialization of object with outer number type * Notes: Test serialization of object with outer number type
* Output-Formats: [*/*]
*/ */
$app->post('/v2/fake/outer/composite', 'FakeApi@fakeOuterCompositeSerialize'); $router->post('/v2/fake/outer/composite', 'FakeApi@fakeOuterCompositeSerialize');
/** /**
* post fakeOuterNumberSerialize * post fakeOuterNumberSerialize
* Summary: * Summary:
* Notes: Test serialization of outer number types * Notes: Test serialization of outer number types
* Output-Formats: [*/*]
*/ */
$app->post('/v2/fake/outer/number', 'FakeApi@fakeOuterNumberSerialize'); $router->post('/v2/fake/outer/number', 'FakeApi@fakeOuterNumberSerialize');
/** /**
* post fakeOuterStringSerialize * post fakeOuterStringSerialize
* Summary: * Summary:
* Notes: Test serialization of outer string types * Notes: Test serialization of outer string types
* Output-Formats: [*/*]
*/ */
$app->post('/v2/fake/outer/string', 'FakeApi@fakeOuterStringSerialize'); $router->post('/v2/fake/outer/string', 'FakeApi@fakeOuterStringSerialize');
/** /**
* patch testClassname * patch testClassname
* Summary: To test class name in snake case * Summary: To test class name in snake case
* Notes: To test class name in snake case * Notes: To test class name in snake case
* Output-Formats: [application/json]
*/ */
$app->patch('/v2/fake_classname_test', 'FakeClassnameTags123Api@testClassname'); $router->patch('/v2/fake_classname_test', 'FakeClassnameTags123Api@testClassname');
/** /**
* post addPet * post addPet
* Summary: Add a new pet to the store * Summary: Add a new pet to the store
* Notes: * Notes:
*/ */
$app->post('/v2/pet', 'PetApi@addPet'); $router->post('/v2/pet', 'PetApi@addPet');
/** /**
* put updatePet * put updatePet
* Summary: Update an existing pet * Summary: Update an existing pet
* Notes: * Notes:
*/ */
$app->put('/v2/pet', 'PetApi@updatePet'); $router->put('/v2/pet', 'PetApi@updatePet');
/** /**
* get findPetsByStatus * get findPetsByStatus
* Summary: Finds Pets by status * Summary: Finds Pets by status
* Notes: Multiple status values can be provided with comma separated strings * Notes: Multiple status values can be provided with comma separated strings
* Output-Formats: [application/xml, application/json]
*/ */
$app->get('/v2/pet/findByStatus', 'PetApi@findPetsByStatus'); $router->get('/v2/pet/findByStatus', 'PetApi@findPetsByStatus');
/** /**
* get findPetsByTags * get findPetsByTags
* Summary: Finds Pets by tags * Summary: Finds Pets by tags
* Notes: Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * Notes: Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
* Output-Formats: [application/xml, application/json]
*/ */
$app->get('/v2/pet/findByTags', 'PetApi@findPetsByTags'); $router->get('/v2/pet/findByTags', 'PetApi@findPetsByTags');
/** /**
* delete deletePet * delete deletePet
* Summary: Deletes a pet * Summary: Deletes a pet
* Notes: * Notes:
*/ */
$app->delete('/v2/pet/{petId}', 'PetApi@deletePet'); $router->delete('/v2/pet/{petId}', 'PetApi@deletePet');
/** /**
* get getPetById * get getPetById
* Summary: Find pet by ID * Summary: Find pet by ID
* Notes: Returns a single pet * Notes: Returns a single pet
* Output-Formats: [application/xml, application/json]
*/ */
$app->get('/v2/pet/{petId}', 'PetApi@getPetById'); $router->get('/v2/pet/{petId}', 'PetApi@getPetById');
/** /**
* post updatePetWithForm * post updatePetWithForm
* Summary: Updates a pet in the store with form data * Summary: Updates a pet in the store with form data
* Notes: * Notes:
*/ */
$app->post('/v2/pet/{petId}', 'PetApi@updatePetWithForm'); $router->post('/v2/pet/{petId}', 'PetApi@updatePetWithForm');
/** /**
* post uploadFile * post uploadFile
* Summary: uploads an image * Summary: uploads an image
* Notes: * Notes:
* Output-Formats: [application/json]
*/ */
$app->post('/v2/pet/{petId}/uploadImage', 'PetApi@uploadFile'); $router->post('/v2/pet/{petId}/uploadImage', 'PetApi@uploadFile');
/** /**
* get getInventory * get getInventory
* Summary: Returns pet inventories by status * Summary: Returns pet inventories by status
* Notes: Returns a map of status codes to quantities * Notes: Returns a map of status codes to quantities
* Output-Formats: [application/json]
*/ */
$app->get('/v2/store/inventory', 'StoreApi@getInventory'); $router->get('/v2/store/inventory', 'StoreApi@getInventory');
/** /**
* post placeOrder * post placeOrder
* Summary: Place an order for a pet * Summary: Place an order for a pet
* Notes: * Notes:
* Output-Formats: [application/xml, application/json]
*/ */
$app->post('/v2/store/order', 'StoreApi@placeOrder'); $router->post('/v2/store/order', 'StoreApi@placeOrder');
/** /**
* delete deleteOrder * delete deleteOrder
* Summary: Delete purchase order by ID * Summary: Delete purchase order by ID
* Notes: For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors * Notes: For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
*/ */
$app->delete('/v2/store/order/{order_id}', 'StoreApi@deleteOrder'); $router->delete('/v2/store/order/{order_id}', 'StoreApi@deleteOrder');
/** /**
* get getOrderById * get getOrderById
* Summary: Find purchase order by ID * Summary: Find purchase order by ID
* Notes: For valid response try integer IDs with value &lt;&#x3D; 5 or &gt; 10. Other values will generated exceptions * Notes: For valid response try integer IDs with value &lt;&#x3D; 5 or &gt; 10. Other values will generated exceptions
* Output-Formats: [application/xml, application/json]
*/ */
$app->get('/v2/store/order/{order_id}', 'StoreApi@getOrderById'); $router->get('/v2/store/order/{order_id}', 'StoreApi@getOrderById');
/** /**
* post createUser * post createUser
* Summary: Create user * Summary: Create user
* Notes: This can only be done by the logged in user. * Notes: This can only be done by the logged in user.
*/ */
$app->post('/v2/user', 'UserApi@createUser'); $router->post('/v2/user', 'UserApi@createUser');
/** /**
* post createUsersWithArrayInput * post createUsersWithArrayInput
* Summary: Creates list of users with given input array * Summary: Creates list of users with given input array
* Notes: * Notes:
*/ */
$app->post('/v2/user/createWithArray', 'UserApi@createUsersWithArrayInput'); $router->post('/v2/user/createWithArray', 'UserApi@createUsersWithArrayInput');
/** /**
* post createUsersWithListInput * post createUsersWithListInput
* Summary: Creates list of users with given input array * Summary: Creates list of users with given input array
* Notes: * Notes:
*/ */
$app->post('/v2/user/createWithList', 'UserApi@createUsersWithListInput'); $router->post('/v2/user/createWithList', 'UserApi@createUsersWithListInput');
/** /**
* get loginUser * get loginUser
* Summary: Logs user into the system * Summary: Logs user into the system
* Notes: * Notes:
* Output-Formats: [application/xml, application/json]
*/ */
$app->get('/v2/user/login', 'UserApi@loginUser'); $router->get('/v2/user/login', 'UserApi@loginUser');
/** /**
* get logoutUser * get logoutUser
* Summary: Logs out current logged in user session * Summary: Logs out current logged in user session
* Notes: * Notes:
*/ */
$app->get('/v2/user/logout', 'UserApi@logoutUser'); $router->get('/v2/user/logout', 'UserApi@logoutUser');
/** /**
* delete deleteUser * delete deleteUser
* Summary: Delete user * Summary: Delete user
* Notes: This can only be done by the logged in user. * Notes: This can only be done by the logged in user.
*/ */
$app->delete('/v2/user/{username}', 'UserApi@deleteUser'); $router->delete('/v2/user/{username}', 'UserApi@deleteUser');
/** /**
* get getUserByName * get getUserByName
* Summary: Get user by user name * Summary: Get user by user name
* Notes: * Notes:
* Output-Formats: [application/xml, application/json]
*/ */
$app->get('/v2/user/{username}', 'UserApi@getUserByName'); $router->get('/v2/user/{username}', 'UserApi@getUserByName');
/** /**
* put updateUser * put updateUser
* Summary: Updated user * Summary: Updated user
* Notes: This can only be done by the logged in user. * Notes: This can only be done by the logged in user.
*/ */
$app->put('/v2/user/{username}', 'UserApi@updateUser'); $router->put('/v2/user/{username}', 'UserApi@updateUser');

View File

@ -0,0 +1,2 @@
*
!.gitignore

View File

@ -0,0 +1,21 @@
<?php
use Laravel\Lumen\Testing\DatabaseMigrations;
use Laravel\Lumen\Testing\DatabaseTransactions;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testExample()
{
$this->get('/');
$this->assertEquals(
$this->app->version(), $this->response->getContent()
);
}
}

View File

@ -0,0 +1,14 @@
<?php
abstract class TestCase extends Laravel\Lumen\Testing\TestCase
{
/**
* Creates the application.
*
* @return \Laravel\Lumen\Application
*/
public function createApplication()
{
return require __DIR__.'/../bootstrap/app.php';
}
}