diff --git a/Modules/Api/app/Http/Controllers/.gitkeep b/Modules/Api/app/Http/Controllers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Modules/Api/app/Http/Controllers/ApiController.php b/Modules/Api/app/Http/Controllers/ApiController.php new file mode 100644 index 0000000..2d7f1e0 --- /dev/null +++ b/Modules/Api/app/Http/Controllers/ApiController.php @@ -0,0 +1,56 @@ +registerCommands(); + $this->registerCommandSchedules(); + $this->registerTranslations(); + $this->registerConfig(); + $this->registerViews(); + $this->loadMigrationsFrom(module_path($this->name, 'database/migrations')); + } + + /** + * Register the service provider. + */ + public function register(): void + { + $this->app->register(EventServiceProvider::class); + $this->app->register(RouteServiceProvider::class); + } + + /** + * Register commands in the format of Command::class + */ + protected function registerCommands(): void + { + // $this->commands([]); + } + + /** + * Register command Schedules. + */ + protected function registerCommandSchedules(): void + { + // $this->app->booted(function () { + // $schedule = $this->app->make(Schedule::class); + // $schedule->command('inspire')->hourly(); + // }); + } + + /** + * Register translations. + */ + public function registerTranslations(): void + { + $langPath = resource_path('lang/modules/'.$this->nameLower); + + if (is_dir($langPath)) { + $this->loadTranslationsFrom($langPath, $this->nameLower); + $this->loadJsonTranslationsFrom($langPath); + } else { + $this->loadTranslationsFrom(module_path($this->name, 'lang'), $this->nameLower); + $this->loadJsonTranslationsFrom(module_path($this->name, 'lang')); + } + } + + /** + * Register config. + */ + protected function registerConfig(): void + { + $configPath = module_path($this->name, config('modules.paths.generator.config.path')); + + if (is_dir($configPath)) { + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configPath)); + + foreach ($iterator as $file) { + if ($file->isFile() && $file->getExtension() === 'php') { + $config = str_replace($configPath.DIRECTORY_SEPARATOR, '', $file->getPathname()); + $config_key = str_replace([DIRECTORY_SEPARATOR, '.php'], ['.', ''], $config); + $segments = explode('.', $this->nameLower.'.'.$config_key); + + // Remove duplicated adjacent segments + $normalized = []; + foreach ($segments as $segment) { + if (end($normalized) !== $segment) { + $normalized[] = $segment; + } + } + + $key = ($config === 'config.php') ? $this->nameLower : implode('.', $normalized); + + $this->publishes([$file->getPathname() => config_path($config)], 'config'); + $this->merge_config_from($file->getPathname(), $key); + } + } + } + } + + /** + * Merge config from the given path recursively. + */ + protected function merge_config_from(string $path, string $key): void + { + $existing = config($key, []); + $module_config = require $path; + + config([$key => array_replace_recursive($existing, $module_config)]); + } + + /** + * Register views. + */ + public function registerViews(): void + { + $viewPath = resource_path('views/modules/'.$this->nameLower); + $sourcePath = module_path($this->name, 'resources/views'); + + $this->publishes([$sourcePath => $viewPath], ['views', $this->nameLower.'-module-views']); + + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower); + + Blade::componentNamespace(config('modules.namespace').'\\' . $this->name . '\\View\\Components', $this->nameLower); + } + + /** + * Get the services provided by the provider. + */ + public function provides(): array + { + return []; + } + + private function getPublishableViewPaths(): array + { + $paths = []; + foreach (config('view.paths') as $path) { + if (is_dir($path.'/modules/'.$this->nameLower)) { + $paths[] = $path.'/modules/'.$this->nameLower; + } + } + + return $paths; + } +} diff --git a/Modules/Api/app/Providers/EventServiceProvider.php b/Modules/Api/app/Providers/EventServiceProvider.php new file mode 100644 index 0000000..7b45106 --- /dev/null +++ b/Modules/Api/app/Providers/EventServiceProvider.php @@ -0,0 +1,27 @@ +> + */ + protected $listen = []; + + /** + * Indicates if events should be discovered. + * + * @var bool + */ + protected static $shouldDiscoverEvents = true; + + /** + * Configure the proper event listeners for email verification. + */ + protected function configureEmailVerification(): void {} +} diff --git a/Modules/Api/app/Providers/RouteServiceProvider.php b/Modules/Api/app/Providers/RouteServiceProvider.php new file mode 100644 index 0000000..f0d2f27 --- /dev/null +++ b/Modules/Api/app/Providers/RouteServiceProvider.php @@ -0,0 +1,50 @@ +mapApiRoutes(); + $this->mapWebRoutes(); + } + + /** + * Define the "web" routes for the application. + * + * These routes all receive session state, CSRF protection, etc. + */ + protected function mapWebRoutes(): void + { + Route::middleware('web')->group(module_path($this->name, '/routes/web.php')); + } + + /** + * Define the "api" routes for the application. + * + * These routes are typically stateless. + */ + protected function mapApiRoutes(): void + { + Route::middleware('api')->prefix('api')->name('api.')->group(module_path($this->name, '/routes/api.php')); + } +} diff --git a/Modules/Api/composer.json b/Modules/Api/composer.json new file mode 100644 index 0000000..f9bf9a5 --- /dev/null +++ b/Modules/Api/composer.json @@ -0,0 +1,30 @@ +{ + "name": "nwidart/api", + "description": "", + "authors": [ + { + "name": "Nicolas Widart", + "email": "n.widart@gmail.com" + } + ], + "extra": { + "laravel": { + "providers": [], + "aliases": { + + } + } + }, + "autoload": { + "psr-4": { + "Modules\\Api\\": "app/", + "Modules\\Api\\Database\\Factories\\": "database/factories/", + "Modules\\Api\\Database\\Seeders\\": "database/seeders/" + } + }, + "autoload-dev": { + "psr-4": { + "Modules\\Api\\Tests\\": "tests/" + } + } +} diff --git a/Modules/Api/config/.gitkeep b/Modules/Api/config/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Modules/Api/config/config.php b/Modules/Api/config/config.php new file mode 100644 index 0000000..d8a8f1f --- /dev/null +++ b/Modules/Api/config/config.php @@ -0,0 +1,5 @@ + 'Api', +]; diff --git a/Modules/Api/database/factories/.gitkeep b/Modules/Api/database/factories/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Modules/Api/database/migrations/.gitkeep b/Modules/Api/database/migrations/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Modules/Api/database/seeders/.gitkeep b/Modules/Api/database/seeders/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Modules/Api/database/seeders/ApiDatabaseSeeder.php b/Modules/Api/database/seeders/ApiDatabaseSeeder.php new file mode 100644 index 0000000..c0085c4 --- /dev/null +++ b/Modules/Api/database/seeders/ApiDatabaseSeeder.php @@ -0,0 +1,16 @@ +call([]); + } +} diff --git a/Modules/Api/module.json b/Modules/Api/module.json new file mode 100644 index 0000000..19b1da3 --- /dev/null +++ b/Modules/Api/module.json @@ -0,0 +1,16 @@ +{ + "name": "modules/api", + "description": "", + "type": "module", + "autoload": { + "psr-4": { + "Modules\\Api\\": "app/" + } + }, + "extra": { + "laravel": { + "providers": [] + } + }, + "require": {} +} diff --git a/Modules/Api/package.json b/Modules/Api/package.json new file mode 100644 index 0000000..d6fbfc8 --- /dev/null +++ b/Modules/Api/package.json @@ -0,0 +1,15 @@ +{ + "private": true, + "type": "module", + "scripts": { + "dev": "vite", + "build": "vite build" + }, + "devDependencies": { + "axios": "^1.1.2", + "laravel-vite-plugin": "^0.7.5", + "sass": "^1.69.5", + "postcss": "^8.3.7", + "vite": "^4.0.0" + } +} diff --git a/Modules/Api/resources/assets/.gitkeep b/Modules/Api/resources/assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Modules/Api/resources/assets/js/app.js b/Modules/Api/resources/assets/js/app.js new file mode 100644 index 0000000..e69de29 diff --git a/Modules/Api/resources/assets/sass/app.scss b/Modules/Api/resources/assets/sass/app.scss new file mode 100644 index 0000000..e69de29 diff --git a/Modules/Api/resources/views/.gitkeep b/Modules/Api/resources/views/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Modules/Api/resources/views/components/layouts/master.blade.php b/Modules/Api/resources/views/components/layouts/master.blade.php new file mode 100644 index 0000000..f6cfc4e --- /dev/null +++ b/Modules/Api/resources/views/components/layouts/master.blade.php @@ -0,0 +1,29 @@ + + + +
+ + + + + +Module: {!! config('api.name') !!}
+