diff --git a/.editorconfig b/.editorconfig index d597de892..258185496 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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 \ No newline at end of file diff --git a/app/Contracts/Modules/ServiceProvider.php b/app/Contracts/Modules/ServiceProvider.php new file mode 100644 index 000000000..9ff82a784 --- /dev/null +++ b/app/Contracts/Modules/ServiceProvider.php @@ -0,0 +1,49 @@ +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 []; + } +} diff --git a/config/modules.php b/config/modules.php index ee070448a..b724fda29 100644 --- a/config/modules.php +++ b/config/modules.php @@ -17,9 +17,10 @@ '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' => [ @@ -27,22 +28,45 @@ '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, @@ -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], @@ -124,7 +149,7 @@ 'cache' => [ 'enabled' => true, 'key' => 'phpvms-modules', - 'lifetime' => 10, + 'lifetime' => 0, ], /* |-------------------------------------------------------------------------- @@ -143,7 +168,7 @@ 'class' => FileActivator::class, 'statuses-file' => config_path('modules_statuses.json'), 'cache-key' => 'activator.installed', - 'cache-lifetime' => 604800, + 'cache-lifetime' => 0, ], ], ]; diff --git a/config/modules_statuses.json b/config/modules_statuses.json index d7b8ddbef..f5ddf9953 100644 --- a/config/modules_statuses.json +++ b/config/modules_statuses.json @@ -5,5 +5,6 @@ "Sample": true, "Updater": true, "VMSAcars": true, - "Vacentral": true -} + "Vacentral": true, + "TestModule": true +} \ No newline at end of file diff --git a/modules/Awards/Providers/AwardServiceProvider.php b/modules/Awards/Providers/AwardServiceProvider.php index 1497163e6..9fbd7c515 100644 --- a/modules/Awards/Providers/AwardServiceProvider.php +++ b/modules/Awards/Providers/AwardServiceProvider.php @@ -2,7 +2,7 @@ namespace Modules\Awards\Providers; -use Illuminate\Support\ServiceProvider; +use App\Contracts\Modules\ServiceProvider; class AwardServiceProvider extends ServiceProvider { diff --git a/modules/Importer/Providers/ImporterServiceProvider.php b/modules/Importer/Providers/ImporterServiceProvider.php index 8a36b204b..6369c455d 100644 --- a/modules/Importer/Providers/ImporterServiceProvider.php +++ b/modules/Importer/Providers/ImporterServiceProvider.php @@ -2,8 +2,8 @@ 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 @@ -11,7 +11,7 @@ class ImporterServiceProvider extends ServiceProvider /** * Boot the application events. */ - public function boot() + public function boot(): void { $this->registerCommands(); $this->registerRoutes(); @@ -20,6 +20,9 @@ public function boot() $this->registerViews(); } + /** + * Register console commands + */ protected function registerCommands() { $this->commands([ @@ -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'); }); } @@ -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 []; - } } diff --git a/modules/Installer/Providers/InstallerServiceProvider.php b/modules/Installer/Providers/InstallerServiceProvider.php index 63ba0b2cb..5150d7cdc 100644 --- a/modules/Installer/Providers/InstallerServiceProvider.php +++ b/modules/Installer/Providers/InstallerServiceProvider.php @@ -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(); diff --git a/resources/stubs/modules/composer.stub b/resources/stubs/modules/composer.stub index 140c27d85..91a1cd370 100644 --- a/resources/stubs/modules/composer.stub +++ b/resources/stubs/modules/composer.stub @@ -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": { diff --git a/resources/stubs/modules/scaffold/config.stub b/resources/stubs/modules/config.stub similarity index 100% rename from resources/stubs/modules/scaffold/config.stub rename to resources/stubs/modules/config.stub diff --git a/resources/stubs/modules/controller-admin.stub b/resources/stubs/modules/controller-admin.stub index 3d92c74fb..323d97f4a 100644 --- a/resources/stubs/modules/controller-admin.stub +++ b/resources/stubs/modules/controller-admin.stub @@ -6,52 +6,71 @@ 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) { @@ -59,8 +78,10 @@ class AdminController extends Controller /** * Remove the specified resource from storage. + * + * @param Request $request */ - public function destroy() + public function destroy(Request $request) { } } diff --git a/resources/stubs/modules/controller-api.stub b/resources/stubs/modules/controller-api.stub index 3beae8878..3de5236e3 100644 --- a/resources/stubs/modules/controller-api.stub +++ b/resources/stubs/modules/controller-api.stub @@ -13,7 +13,9 @@ class ApiController extends Controller { /** * Just send out a message + * * @param Request $request + * * @return mixed */ public function index(Request $request) @@ -23,7 +25,9 @@ class ApiController extends Controller /** * Handles /hello + * * @param Request $request + * * @return mixed */ public function hello(Request $request) diff --git a/resources/stubs/modules/controller-index.stub b/resources/stubs/modules/controller-index.stub new file mode 100644 index 000000000..13a559695 --- /dev/null +++ b/resources/stubs/modules/controller-index.stub @@ -0,0 +1,90 @@ +moduleSvc = app('App\Services\ModuleService'); + + $this->registerTranslations(); + $this->registerConfig(); + $this->registerViews(); + + $this->registerLinks(); + + // Uncomment this if you have migrations + // $this->loadMigrationsFrom(__DIR__ . '/../$MIGRATIONS_PATH$'); + } /** * Register the service provider. - * - * @return void */ public function register() { @@ -28,12 +39,55 @@ class $CLASS$ extends ServiceProvider } /** - * Get the services provided by the provider. - * - * @return array + * Add module links here + */ + public function registerLinks(): void + { + // Show this link if logged in + // $this->moduleSvc->addFrontendLink('$STUDLY_NAME$', '/$LOWER_NAME$', '', $logged_in=true); + + // Admin links: + $this->moduleSvc->addAdminLink('$STUDLY_NAME$', '/admin/$LOWER_NAME$'); + } + + /** + * Register config. */ - public function provides() + protected function registerConfig() { - return []; + $this->publishes([ + __DIR__.'/../Config/config.php' => config_path('$LOWER_NAME$.php'), + ], '$LOWER_NAME$'); + + $this->mergeConfigFrom(__DIR__.'/../Config/config.php', '$LOWER_NAME$'); + } + + /** + * Register views. + */ + public function registerViews() + { + $viewPath = resource_path('views/modules/$LOWER_NAME$'); + $sourcePath = __DIR__.'/../Resources/views'; + + $this->publishes([$sourcePath => $viewPath],'views'); + + $this->loadViewsFrom(array_merge(array_map(function ($path) { + return $path . '/modules/$LOWER_NAME$'; + }, \Config::get('view.paths')), [$sourcePath]), '$LOWER_NAME$'); + } + + /** + * Register translations. + */ + public function registerTranslations() + { + $langPath = resource_path('lang/modules/$LOWER_NAME$'); + + if (is_dir($langPath)) { + $this->loadTranslationsFrom($langPath, '$LOWER_NAME$'); + } else { + $this->loadTranslationsFrom(__DIR__ .'/../Resources/lang', '$LOWER_NAME$'); + } } } diff --git a/resources/stubs/modules/route-provider.stub b/resources/stubs/modules/route-provider.stub index 45d782dcf..13307df06 100644 --- a/resources/stubs/modules/route-provider.stub +++ b/resources/stubs/modules/route-provider.stub @@ -4,19 +4,19 @@ namespace $NAMESPACE$; use Illuminate\Routing\Router; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; +use Illuminate\Support\Facades\Route; /** - * Class $CLASS$ - * @package $NAMESPACE$ + * Register the routes required for your module here */ -class $CLASS$ extends ServiceProvider +class RouteServiceProvider extends ServiceProvider { /** * The root namespace to assume when generating URLs to actions. * * @var string */ - protected $rootUrlNamespace = '$MODULE_NAMESPACE$\$MODULE$\Http\Controllers'; + protected $namespace = '$MODULE_NAMESPACE$\$MODULE$\$CONTROLLER_NAMESPACE$'; /** * Called before routes are registered. @@ -34,12 +34,62 @@ class $CLASS$ extends ServiceProvider /** * Define the routes for the application. * + * @param \Illuminate\Routing\Router $router + * * @return void */ public function map(Router $router) { - // if (!app()->routesAreCached()) { - // require __DIR__ . '$ROUTES_PATH$'; - // } + $this->registerWebRoutes(); + $this->registerAdminRoutes(); + $this->registerApiRoutes(); + } + + /** + * + */ + protected function registerWebRoutes(): void + { + $config = [ + 'as' => '$LOWER_NAME$.', + 'prefix' => '$LOWER_NAME$', + 'namespace' => $this->namespace.'\Frontend', + 'middleware' => ['web'], + ]; + + Route::group($config, function() { + $this->loadRoutesFrom(__DIR__.'/../Http/Routes/web.php'); + }); + } + + protected function registerAdminRoutes(): void + { + $config = [ + 'as' => 'admin.$LOWER_NAME$.', + 'prefix' => 'admin/$LOWER_NAME$', + 'namespace' => $this->namespace.'\Admin', + 'middleware' => ['web', 'role:admin'], + ]; + + Route::group($config, function() { + $this->loadRoutesFrom(__DIR__.'/../Http/Routes/web.php'); + }); + } + + /** + * Register any API routes your module has. Remove this if you aren't using any + */ + protected function registerApiRoutes(): void + { + $config = [ + 'as' => 'admin.$LOWER_NAME$.', + 'prefix' => 'admin/$LOWER_NAME$', + 'namespace' => $this->namespace.'\Api', + 'middleware' => ['api'], + ]; + + Route::group($config, function() { + $this->loadRoutesFrom(__DIR__.'/../Http/Routes/api.php'); + }); } } diff --git a/resources/stubs/modules/routes-admin.stub b/resources/stubs/modules/routes-admin.stub index ad8120c70..4a49d8f64 100644 --- a/resources/stubs/modules/routes-admin.stub +++ b/resources/stubs/modules/routes-admin.stub @@ -1,6 +1,4 @@ [ - 'role:user' # leave blank to make this public -]], function() { - # all your routes are prefixed with the above prefix - # e.g. yoursite.com/sample - Route::get('/', '$STUDLY_NAME$Controller@index'); -}); +Route::get('/', '$STUDLY_NAME$Controller@index'); + +/* + * To register a route that needs to be authentication, wrap it in a + * Route::group() with the auth middleware + */ +// Route::group(['middleware' => 'auth'], function() { +// Route::get('/', '$STUDLY_NAME$Controller@index'); +// }) diff --git a/resources/stubs/modules/scaffold/provider.stub b/resources/stubs/modules/scaffold/provider.stub deleted file mode 100644 index 2f0040e1e..000000000 --- a/resources/stubs/modules/scaffold/provider.stub +++ /dev/null @@ -1,152 +0,0 @@ -moduleSvc = app('App\Services\ModuleService'); - - $this->registerRoutes(); - $this->registerTranslations(); - $this->registerConfig(); - $this->registerViews(); - - $this->registerLinks(); - - $this->loadMigrationsFrom(__DIR__ . '/../$MIGRATIONS_PATH$'); - } - - /** - * Register the service provider. - */ - public function register() - { - // - } - - /** - * Add module links here - */ - public function registerLinks() - { - // Show this link if logged in - // $this->moduleSvc->addFrontendLink('$STUDLY_NAME$', '/$LOWER_NAME$', '', $logged_in=true); - - // Admin links: - $this->moduleSvc->addAdminLink('$STUDLY_NAME$', '/admin/$LOWER_NAME$'); - } - - /** - * Register the routes - */ - protected function registerRoutes() - { - /** - * Routes for the frontend - */ - Route::group([ - 'as' => '$LOWER_NAME$.', - 'prefix' => '$LOWER_NAME$', - // If you want a RESTful module, change this to 'api' - 'middleware' => ['web'], - 'namespace' => '$MODULE_NAMESPACE$\$STUDLY_NAME$\Http\Controllers' - ], function() { - $this->loadRoutesFrom(__DIR__ . '/../Http/Routes/web.php'); - }); - - /** - * Routes for the admin - */ - Route::group([ - 'as' => '$LOWER_NAME$.', - 'prefix' => 'admin/$LOWER_NAME$', - // If you want a RESTful module, change this to 'api' - 'middleware' => ['web', 'role:admin'], - 'namespace' => '$MODULE_NAMESPACE$\$STUDLY_NAME$\Http\Controllers\Admin' - ], function() { - $this->loadRoutesFrom(__DIR__ . '/../Http/Routes/admin.php'); - }); - - /** - * Routes for an API - */ - Route::group([ - 'as' => '$LOWER_NAME$.', - 'prefix' => 'api/$LOWER_NAME$', - // If you want a RESTful module, change this to 'api' - 'middleware' => ['api'], - 'namespace' => '$MODULE_NAMESPACE$\$STUDLY_NAME$\Http\Controllers\Api' - ], function() { - $this->loadRoutesFrom(__DIR__ . '/../Http/Routes/api.php'); - }); - } - - /** - * Register config. - */ - protected function registerConfig() - { - $this->publishes([ - __DIR__.'/../$PATH_CONFIG$/config.php' => config_path('$LOWER_NAME$.php'), - ], '$LOWER_NAME$'); - - $this->mergeConfigFrom( - __DIR__.'/../$PATH_CONFIG$/config.php', '$LOWER_NAME$' - ); - } - - /** - * Register views. - */ - public function registerViews() - { - $viewPath = resource_path('views/modules/$LOWER_NAME$'); - $sourcePath = __DIR__.'/../$PATH_VIEWS$'; - - $this->publishes([ - $sourcePath => $viewPath - ],'views'); - - $this->loadViewsFrom(array_merge(array_map(function ($path) { - return $path . '/modules/$LOWER_NAME$'; - }, \Config::get('view.paths')), [$sourcePath]), '$LOWER_NAME$'); - } - - /** - * Register translations. - */ - public function registerTranslations() - { - $langPath = resource_path('lang/modules/$LOWER_NAME$'); - - if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, '$LOWER_NAME$'); - } else { - $this->loadTranslationsFrom(__DIR__ .'/../$PATH_LANG$', '$LOWER_NAME$'); - } - } - - /** - * Get the services provided by the provider. - */ - public function provides() - { - return []; - } -}