Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update module generation #714 #716

Merged
merged 14 commits into from
Sep 20, 2020
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ indent_style = tab
# Matches the exact files either package.json or .travis.yml
[{package.json, .travis.yml}]
indent_style = space
indent_size = 2
indent_size = 2
49 changes: 49 additions & 0 deletions app/Contracts/Modules/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace App\Contracts\Modules;

/**
* Base class for module service providers
* Add-on module service providers must extend this class. Docs on Service Providers:
* https://laravel.com/docs/7.x/providers
*
* For a sample service provider, view the sample module one:
* https://github.com/nabeelio/phpvms-module/blob/master/Providers/SampleServiceProvider.php
*/
abstract class ServiceProvider extends \Illuminate\Support\ServiceProvider
{
/**
* A boot method is required, even if it doesn't do anything.
* https://laravel.com/docs/7.x/providers#the-boot-method
*
* This is normally where you'd register the routes or other startup tasks for your module
*/
public function boot(): void
{
}

/**
* This is required to register the links in either the public or admin toolbar
* For example, adding a frontend link:
*
* $this->moduleSvc->addFrontendLink('Sample', '/sample', '', $logged_in=true);
*
* Or an admin link:
*
* $this->moduleSvc->addAdminLink('Sample', '/admin/sample');
*/
public function registerLinks(): void
{
}

/**
* Deferred providers:
* https://laravel.com/docs/7.x/providers#deferred-providers
*
* @return array
*/
public function provides(): array
{
return [];
}
}
65 changes: 45 additions & 20 deletions config/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,56 @@
'views/frontend' => 'Resources/views/layouts/frontend.blade.php',
'views/admin' => 'Resources/views/layouts/admin.blade.php',
'listener-test' => 'Listeners/TestEventListener.php',
'controller-index' => 'Http/Controllers/Frontend/IndexController.php',
'controller-api' => 'Http/Controllers/Api/ApiController.php',
'controller-admin' => 'Http/Controllers/Admin/AdminController.php',
'scaffold/config' => 'Config/config.php',
'config' => 'Config/config.php',
'composer' => 'composer.json',
],
'replacements' => [
'start' => ['LOWER_NAME', 'ROUTES_LOCATION'],
'routes' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
'routes-api' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
'json' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
'event-service-provider' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
'listener-test' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
'views/index' => ['LOWER_NAME'],
'views/index-admin' => ['LOWER_NAME', 'STUDLY_NAME'],
'views/frontend' => ['STUDLY_NAME'],
'views/admin' => ['STUDLY_NAME'],
'controller-admin' => ['MODULE_NAMESPACE', 'STUDLY_NAME', 'CLASS_NAMESPACE', 'LOWER_NAME'],
'controller-api' => ['MODULE_NAMESPACE', 'STUDLY_NAME', 'CLASS_NAMESPACE', 'LOWER_NAME'],
'scaffold/config' => ['STUDLY_NAME'],
'composer' => [
'provider' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
'event-service-provider' => [
'LOWER_NAME',
'STUDLY_NAME',
'MODULE_NAMESPACE',
'CLASS_NAMESPACE',
],
'listener-test' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
'views/index' => ['LOWER_NAME'],
'views/index-admin' => ['LOWER_NAME', 'STUDLY_NAME'],
'views/frontend' => ['STUDLY_NAME'],
'views/admin' => ['STUDLY_NAME'],
'controller-index' => [
'MODULE_NAMESPACE',
'STUDLY_NAME',
'CLASS_NAMESPACE',
'LOWER_NAME',
],
'controller-admin' => [
'MODULE_NAMESPACE',
'STUDLY_NAME',
'CLASS_NAMESPACE',
'LOWER_NAME',
],
'controller-api' => [
'MODULE_NAMESPACE',
'STUDLY_NAME',
'CLASS_NAMESPACE',
'LOWER_NAME',
],
'config' => ['STUDLY_NAME'],
'composer' => [
'LOWER_NAME',
'STUDLY_NAME',
'VENDOR',
'AUTHOR_NAME',
'AUTHOR_EMAIL',
'MODULE_NAMESPACE',
'PROVIDER_NAMESPACE',
],
],
'gitkeep' => false,
Expand All @@ -52,15 +76,16 @@
'assets' => public_path('modules'),
'migration' => base_path('database/migrations'),
'generator' => [
'config' => ['path' => 'Config', 'generate' => true],
'command' => ['path' => 'Console', 'generate' => true],
'migration' => ['path' => 'Database/migrations', 'generate' => true],
'seeds' => ['path' => 'Database/seeds', 'generate' => true],
'factory' => ['path' => 'Database/factories', 'generate' => true],
'model' => ['path' => 'Models', 'generate' => true],
'controller' => ['path' => 'Http/Controllers', 'generate' => true],
'config' => ['path' => 'Config', 'generate' => true],
'command' => ['path' => 'Console', 'generate' => true],
'migration' => ['path' => 'Database/migrations', 'generate' => true],
'seeds' => ['path' => 'Database/seeds', 'generate' => true],
'factory' => ['path' => 'Database/factories', 'generate' => true],
'model' => ['path' => 'Models', 'generate' => true],
//'controller' => ['path' => 'Http/Controllers', 'generate' => true],
'controller-admin' => ['path' => 'Http/Controllers/Admin', 'generate' => true],
'controller-api' => ['path' => 'Http/Controllers/Api', 'generate' => true],
'controller-index' => ['path' => 'Http/Controllers/Frontend', 'generate' => true],
'filter' => ['path' => 'Http/Middleware', 'generate' => true],
'request' => ['path' => 'Http/Requests', 'generate' => true],
'routes' => ['path' => 'Http/Routes', 'generate' => true],
Expand Down Expand Up @@ -124,7 +149,7 @@
'cache' => [
'enabled' => true,
'key' => 'phpvms-modules',
'lifetime' => 10,
'lifetime' => 0,
],
/*
|--------------------------------------------------------------------------
Expand All @@ -143,7 +168,7 @@
'class' => FileActivator::class,
'statuses-file' => config_path('modules_statuses.json'),
'cache-key' => 'activator.installed',
'cache-lifetime' => 604800,
'cache-lifetime' => 0,
],
],
];
5 changes: 3 additions & 2 deletions config/modules_statuses.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"Sample": true,
"Updater": true,
"VMSAcars": true,
"Vacentral": true
}
"Vacentral": true,
"TestModule": true
}
2 changes: 1 addition & 1 deletion modules/Awards/Providers/AwardServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Modules\Awards\Providers;

use Illuminate\Support\ServiceProvider;
use App\Contracts\Modules\ServiceProvider;

class AwardServiceProvider extends ServiceProvider
{
Expand Down
16 changes: 5 additions & 11 deletions modules/Importer/Providers/ImporterServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace Modules\Importer\Providers;

use App\Contracts\Modules\ServiceProvider;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use Modules\Importer\Console\Commands\ImportFromClassicCommand;

class ImporterServiceProvider extends ServiceProvider
{
/**
* Boot the application events.
*/
public function boot()
public function boot(): void
{
$this->registerCommands();
$this->registerRoutes();
Expand All @@ -20,6 +20,9 @@ public function boot()
$this->registerViews();
}

/**
* Register console commands
*/
protected function registerCommands()
{
$this->commands([
Expand All @@ -44,7 +47,6 @@ protected function registerRoutes()

// Run the actual importer process. Additional middleware
Route::post('/run', 'ImporterController@run')->middleware('api')->name('run');

Route::post('/complete', 'ImporterController@complete')->name('complete');
});
}
Expand Down Expand Up @@ -91,12 +93,4 @@ public function registerTranslations()
$this->loadTranslationsFrom(__DIR__.'/../Resources/lang', 'importer');
}
}

/**
* Get the services provided by the provider.
*/
public function provides(): array
{
return [];
}
}
4 changes: 2 additions & 2 deletions modules/Installer/Providers/InstallerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace Modules\Installer\Providers;

use App\Contracts\Modules\ServiceProvider;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;

class InstallerServiceProvider extends ServiceProvider
{
/**
* Boot the application events.
*/
public function boot()
public function boot(): void
{
$this->registerRoutes();
$this->registerTranslations();
Expand Down
5 changes: 3 additions & 2 deletions resources/stubs/modules/composer.stub
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
"extra": {
"laravel": {
"providers": [
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\Providers\\$STUDLY_NAME$ServiceProvider",
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\Providers\\EventServiceProvider"
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\Providers\\AppServiceProvider",
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\Providers\\EventServiceProvider",
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\Providers\\RouteServiceProvider"
],
"aliases": {

Expand Down
43 changes: 32 additions & 11 deletions resources/stubs/modules/controller-admin.stub
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,82 @@ use App\Contracts\Controller;
use Illuminate\Http\Request;

/**
* Class AdminController
* @package $MODULE_NAMESPACE$\$STUDLY_NAME$\Http\Controllers\Admin
* Admin controller
*/
class AdminController extends Controller
{
/**
* Display a listing of the resource.
*
* @param Request $request
*
* @return mixed
*/
public function index()
public function index(Request $request)
{
return view('$LOWER_NAME$::admin.index');
}

/**
* Show the form for creating a new resource.
*
* @param Request $request
*
* @return mixed
*/
public function create()
public function create(Request $request)
{
return view('$LOWER_NAME$::admin.create');
}

/**
* Store a newly created resource in storage.
*
* @param Request $request
*/
public function store(Request $request)
{
}

/**
* Show the specified resource.
* Show the form for editing the specified resource.
*
* @param Request $request
*
* @return mixed
*/
public function show()
public function edit(Request $request)
{
return view('$LOWER_NAME$::admin.show');
return view('$LOWER_NAME$::admin.edit');
}

/**
* Show the form for editing the specified resource.
* Show the specified resource.
*
* @param Request $request
*
* @return mixed
*/
public function edit()
public function show(Request $request)
{
return view('$LOWER_NAME$::admin.edit');
return view('$LOWER_NAME$::admin.show');
}

/**
* Update the specified resource in storage.
*
* @param Request $request
*/
public function update(Request $request)
{
}

/**
* Remove the specified resource from storage.
*
* @param Request $request
*/
public function destroy()
public function destroy(Request $request)
{
}
}
4 changes: 4 additions & 0 deletions resources/stubs/modules/controller-api.stub
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class ApiController extends Controller
{
/**
* Just send out a message
*
* @param Request $request
*
* @return mixed
*/
public function index(Request $request)
Expand All @@ -23,7 +25,9 @@ class ApiController extends Controller

/**
* Handles /hello
*
* @param Request $request
*
* @return mixed
*/
public function hello(Request $request)
Expand Down
Loading