Skip to content

Commit 655d046

Browse files
wing328TiFu
authored andcommitted
[PHP-Lumen] Lumen 5.6 support (OpenAPITools#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
1 parent 260ee8f commit 655d046

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+885
-100
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpLumenServerCodegen.java

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,37 @@ public PhpLumenServerCodegen() {
9393
* entire object tree available. If the input file has a suffix of `.mustache
9494
* it will be processed by the template engine. Otherwise, it will be copied
9595
*/
96-
supportingFiles.add(new SupportingFile("composer.mustache", srcBasePath, "composer.json"));
97-
supportingFiles.add(new SupportingFile("readme.md", srcBasePath, "readme.md"));
98-
supportingFiles.add(new SupportingFile("app.php", srcBasePath + File.separator + "bootstrap", "app.php"));
99-
supportingFiles.add(new SupportingFile("index.php", srcBasePath + File.separator + "public", "index.php"));
100-
supportingFiles.add(new SupportingFile("User.php", srcBasePath + File.separator + "app", "User.php"));
101-
supportingFiles.add(new SupportingFile("Kernel.php", srcBasePath + File.separator + "app" + File.separator + "Console", "Kernel.php"));
102-
supportingFiles.add(new SupportingFile("Handler.php", srcBasePath + File.separator + "app" + File.separator + "Exceptions", "Handler.php"));
103-
supportingFiles.add(new SupportingFile("routes.mustache", srcBasePath + File.separator + "app" + File.separator + "Http", "routes.php"));
104-
supportingFiles.add(new SupportingFile("Controller.php", srcBasePath + File.separator + "app" + File.separator + "Http" + File.separator + "Controllers" + File.separator, "Controller.php"));
105-
supportingFiles.add(new SupportingFile("Authenticate.php", srcBasePath + File.separator + "app" + File.separator + "Http" + File.separator + "Middleware" + File.separator, "Authenticate.php"));
106-
96+
supportingFiles.add(new SupportingFile(".env.example", packagePath + File.separator + srcBasePath, ".env.example"));
97+
supportingFiles.add(new SupportingFile("storage_logs_.gitignore", packagePath + File.separator + srcBasePath + File.separator + "storage" + File.separator + "logs", ".gitignore"));
98+
supportingFiles.add(new SupportingFile("artisan", packagePath + File.separator + srcBasePath, "artisan"));
99+
supportingFiles.add(new SupportingFile("composer.mustache", packagePath + File.separator + srcBasePath, "composer.json"));
100+
supportingFiles.add(new SupportingFile("readme.md", packagePath + File.separator + srcBasePath, "readme.md"));
101+
supportingFiles.add(new SupportingFile("User.php", packagePath + File.separator + srcBasePath + File.separator + "app", "User.php"));
102+
supportingFiles.add(new SupportingFile("Kernel.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Console", "Kernel.php"));
103+
supportingFiles.add(new SupportingFile(".gitkeep", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Console" + File.separator + "Commands", ".gitkeep"));
104+
supportingFiles.add(new SupportingFile("Event.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Events", "Event.php"));
105+
supportingFiles.add(new SupportingFile("ExampleEvent.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Events", "ExampleEvent.php"));
106+
supportingFiles.add(new SupportingFile("Handler.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Exceptions", "Handler.php"));
107+
supportingFiles.add(new SupportingFile("Controller.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Http" + File.separator + "Controllers" + File.separator, "Controller.php"));
108+
supportingFiles.add(new SupportingFile("ExampleController.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Http" + File.separator + "Controllers" + File.separator, "ExampleController.php"));
109+
supportingFiles.add(new SupportingFile("Authenticate.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Http" + File.separator + "Middleware" + File.separator, "Authenticate.php"));
110+
supportingFiles.add(new SupportingFile("ExampleMiddleware.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Http" + File.separator + "Middleware" + File.separator, "ExampleMiddleware.php"));
111+
supportingFiles.add(new SupportingFile("ExampleJob.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Jobs", "ExampleJob.php"));
112+
supportingFiles.add(new SupportingFile("Job.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Jobs", "Job.php"));
113+
supportingFiles.add(new SupportingFile("ExampleListener.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Listeners", "ExampleListener.php"));
114+
supportingFiles.add(new SupportingFile("AppServiceProvider.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Providers", "AppServiceProvider.php"));
115+
supportingFiles.add(new SupportingFile("AuthServiceProvider.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Providers", "AuthServiceProvider.php"));
116+
supportingFiles.add(new SupportingFile("EventServiceProvider.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Providers", "EventServiceProvider.php"));
117+
supportingFiles.add(new SupportingFile("app.php", packagePath + File.separator + srcBasePath + File.separator + "bootstrap", "app.php"));
118+
supportingFiles.add(new SupportingFile("ModelFactory.php", packagePath + File.separator + srcBasePath + File.separator + "database" + File.separator + "factories", "ModelFactory.php"));
119+
supportingFiles.add(new SupportingFile(".gitkeep", packagePath + File.separator + srcBasePath + File.separator + "database" + File.separator + "migrations", ".gitkeep"));
120+
supportingFiles.add(new SupportingFile("DatabaseSeeder.php", packagePath + File.separator + srcBasePath + File.separator + "database" + File.separator + "seeds", "DatabaseSeeder.php"));
121+
supportingFiles.add(new SupportingFile(".htaccess", packagePath + File.separator + srcBasePath + File.separator + "public", ".htaccess"));
122+
supportingFiles.add(new SupportingFile("index.php", packagePath + File.separator + srcBasePath + File.separator + "public", "index.php"));
123+
supportingFiles.add(new SupportingFile(".gitkeep", packagePath + File.separator + srcBasePath + File.separator + "resources" + File.separator + "views", ".gitkeep"));
124+
supportingFiles.add(new SupportingFile("routes.mustache", packagePath + File.separator + srcBasePath + File.separator + "routes", "web.php"));
125+
supportingFiles.add(new SupportingFile("ExampleTest.php", packagePath + File.separator + srcBasePath + File.separator + "tests", "ExampleTest.php"));
126+
supportingFiles.add(new SupportingFile("TestCase.php", packagePath + File.separator + srcBasePath + File.separator + "tests", "TestCase.php"));
107127
}
108128

109129
// override with any special post-processing
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
APP_ENV=local
2+
APP_DEBUG=true
3+
APP_KEY=
4+
APP_TIMEZONE=UTC
5+
6+
LOG_CHANNEL=stack
7+
LOG_SLACK_WEBHOOK_URL=
8+
9+
DB_CONNECTION=mysql
10+
DB_HOST=127.0.0.1
11+
DB_PORT=3306
12+
DB_DATABASE=homestead
13+
DB_USERNAME=homestead
14+
DB_PASSWORD=secret
15+
16+
CACHE_DRIVER=file
17+
QUEUE_DRIVER=sync

modules/openapi-generator/src/main/resources/lumen/.gitkeep

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<IfModule mod_rewrite.c>
2+
<IfModule mod_negotiation.c>
3+
Options -MultiViews -Indexes
4+
</IfModule>
5+
6+
RewriteEngine On
7+
8+
# Handle Authorization Header
9+
RewriteCond %{HTTP:Authorization} .
10+
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
11+
12+
# Redirect Trailing Slashes If Not A Folder...
13+
RewriteCond %{REQUEST_FILENAME} !-d
14+
RewriteCond %{REQUEST_URI} (.+)/$
15+
RewriteRule ^ %1 [L,R=301]
16+
17+
# Handle Front Controller...
18+
RewriteCond %{REQUEST_FILENAME} !-d
19+
RewriteCond %{REQUEST_FILENAME} !-f
20+
RewriteRule ^ index.php [L]
21+
</IfModule>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace App\Providers;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
7+
class AppServiceProvider extends ServiceProvider
8+
{
9+
/**
10+
* Register any application services.
11+
*
12+
* @return void
13+
*/
14+
public function register()
15+
{
16+
//
17+
}
18+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace App\Providers;
4+
5+
use App\User;
6+
use Illuminate\Support\Facades\Gate;
7+
use Illuminate\Support\ServiceProvider;
8+
9+
class AuthServiceProvider extends ServiceProvider
10+
{
11+
/**
12+
* Register any application services.
13+
*
14+
* @return void
15+
*/
16+
public function register()
17+
{
18+
//
19+
}
20+
21+
/**
22+
* Boot the authentication services for the application.
23+
*
24+
* @return void
25+
*/
26+
public function boot()
27+
{
28+
// Here you may define how you wish users to be authenticated for your Lumen
29+
// application. The callback which receives the incoming request instance
30+
// should return either a User instance or null. You're free to obtain
31+
// the User instance via an API token or any other method necessary.
32+
33+
$this->app['auth']->viaRequest('api', function ($request) {
34+
if ($request->input('api_token')) {
35+
return User::where('api_token', $request->input('api_token'))->first();
36+
}
37+
});
38+
}
39+
}

modules/openapi-generator/src/main/resources/lumen/Authenticate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
/**
3+
/*
44
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
55
* https://openapi-generator.tech
66
* Do not edit the class manually.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use Illuminate\Database\Seeder;
4+
5+
class DatabaseSeeder extends Seeder
6+
{
7+
/**
8+
* Run the database seeds.
9+
*
10+
* @return void
11+
*/
12+
public function run()
13+
{
14+
// $this->call('UsersTableSeeder');
15+
}
16+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App\Events;
4+
5+
use Illuminate\Queue\SerializesModels;
6+
7+
abstract class Event
8+
{
9+
use SerializesModels;
10+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Providers;
4+
5+
use Laravel\Lumen\Providers\EventServiceProvider as ServiceProvider;
6+
7+
class EventServiceProvider extends ServiceProvider
8+
{
9+
/**
10+
* The event listener mappings for the application.
11+
*
12+
* @var array
13+
*/
14+
protected $listen = [
15+
'App\Events\ExampleEvent' => [
16+
'App\Listeners\ExampleListener',
17+
],
18+
];
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
class ExampleController extends Controller
6+
{
7+
/**
8+
* Create a new controller instance.
9+
*
10+
* @return void
11+
*/
12+
public function __construct()
13+
{
14+
//
15+
}
16+
17+
//
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace App\Events;
4+
5+
class ExampleEvent extends Event
6+
{
7+
/**
8+
* Create a new event instance.
9+
*
10+
* @return void
11+
*/
12+
public function __construct()
13+
{
14+
//
15+
}
16+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace App\Jobs;
4+
5+
class ExampleJob extends Job
6+
{
7+
/**
8+
* Create a new job instance.
9+
*
10+
* @return void
11+
*/
12+
public function __construct()
13+
{
14+
//
15+
}
16+
17+
/**
18+
* Execute the job.
19+
*
20+
* @return void
21+
*/
22+
public function handle()
23+
{
24+
//
25+
}
26+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace App\Listeners;
4+
5+
use App\Events\ExampleEvent;
6+
use Illuminate\Queue\InteractsWithQueue;
7+
use Illuminate\Contracts\Queue\ShouldQueue;
8+
9+
class ExampleListener
10+
{
11+
/**
12+
* Create the event listener.
13+
*
14+
* @return void
15+
*/
16+
public function __construct()
17+
{
18+
//
19+
}
20+
21+
/**
22+
* Handle the event.
23+
*
24+
* @param ExampleEvent $event
25+
* @return void
26+
*/
27+
public function handle(ExampleEvent $event)
28+
{
29+
//
30+
}
31+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use Closure;
6+
7+
class ExampleMiddleware
8+
{
9+
/**
10+
* Handle an incoming request.
11+
*
12+
* @param \Illuminate\Http\Request $request
13+
* @param \Closure $next
14+
* @return mixed
15+
*/
16+
public function handle($request, Closure $next)
17+
{
18+
return $next($request);
19+
}
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
use Laravel\Lumen\Testing\DatabaseMigrations;
4+
use Laravel\Lumen\Testing\DatabaseTransactions;
5+
6+
class ExampleTest extends TestCase
7+
{
8+
/**
9+
* A basic test example.
10+
*
11+
* @return void
12+
*/
13+
public function testExample()
14+
{
15+
$this->get('/');
16+
17+
$this->assertEquals(
18+
$this->app->version(), $this->response->getContent()
19+
);
20+
}
21+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace App\Jobs;
4+
5+
use Illuminate\Bus\Queueable;
6+
use Illuminate\Queue\SerializesModels;
7+
use Illuminate\Queue\InteractsWithQueue;
8+
use Illuminate\Contracts\Queue\ShouldQueue;
9+
10+
abstract class Job implements ShouldQueue
11+
{
12+
/*
13+
|--------------------------------------------------------------------------
14+
| Queueable Jobs
15+
|--------------------------------------------------------------------------
16+
|
17+
| This job base class provides a central location to place any logic that
18+
| is shared across all of your jobs. The trait included with the class
19+
| provides access to the "queueOn" and "delay" queue helper methods.
20+
|
21+
*/
22+
23+
use InteractsWithQueue, Queueable, SerializesModels;
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
|--------------------------------------------------------------------------
5+
| Model Factories
6+
|--------------------------------------------------------------------------
7+
|
8+
| Here you may define all of your model factories. Model factories give
9+
| you a convenient way to create models for testing and seeding your
10+
| database. Just tell the factory how a default model should look.
11+
|
12+
*/
13+
14+
$factory->define(App\User::class, function (Faker\Generator $faker) {
15+
return [
16+
'name' => $faker->name,
17+
'email' => $faker->email,
18+
];
19+
});

0 commit comments

Comments
 (0)