Skip to content

Commit d2f132a

Browse files
committed
.
1 parent 9f01ff4 commit d2f132a

File tree

28 files changed

+479
-1
lines changed

28 files changed

+479
-1
lines changed

README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

app/Http/Controllers/.gitkeep

Whitespace-only changes.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace Modules\TestingModule\Http\Controllers;
4+
5+
use App\Http\Controllers\Controller;
6+
use Illuminate\Http\Request;
7+
8+
class TestingModuleController extends Controller
9+
{
10+
/**
11+
* Display a listing of the resource.
12+
*/
13+
public function index()
14+
{
15+
return view('testingmodule::index');
16+
}
17+
18+
/**
19+
* Show the form for creating a new resource.
20+
*/
21+
public function create()
22+
{
23+
return view('testingmodule::create');
24+
}
25+
26+
/**
27+
* Store a newly created resource in storage.
28+
*/
29+
public function store(Request $request) {}
30+
31+
/**
32+
* Show the specified resource.
33+
*/
34+
public function show($id)
35+
{
36+
return view('testingmodule::show');
37+
}
38+
39+
/**
40+
* Show the form for editing the specified resource.
41+
*/
42+
public function edit($id)
43+
{
44+
return view('testingmodule::edit');
45+
}
46+
47+
/**
48+
* Update the specified resource in storage.
49+
*/
50+
public function update(Request $request, $id) {}
51+
52+
/**
53+
* Remove the specified resource from storage.
54+
*/
55+
public function destroy($id) {}
56+
}

app/Providers/.gitkeep

Whitespace-only changes.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Modules\TestingModule\Providers;
4+
5+
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
6+
7+
class EventServiceProvider extends ServiceProvider
8+
{
9+
/**
10+
* The event handler mappings for the application.
11+
*
12+
* @var array<string, array<int, string>>
13+
*/
14+
protected $listen = [];
15+
16+
/**
17+
* Indicates if events should be discovered.
18+
*
19+
* @var bool
20+
*/
21+
protected static $shouldDiscoverEvents = true;
22+
23+
/**
24+
* Configure the proper event listeners for email verification.
25+
*/
26+
protected function configureEmailVerification(): void {}
27+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Modules\TestingModule\Providers;
4+
5+
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
6+
use Illuminate\Support\Facades\Route;
7+
8+
class RouteServiceProvider extends ServiceProvider
9+
{
10+
protected string $name = 'TestingModule';
11+
12+
/**
13+
* Called before routes are registered.
14+
*
15+
* Register any model bindings or pattern based filters.
16+
*/
17+
public function boot(): void
18+
{
19+
parent::boot();
20+
}
21+
22+
/**
23+
* Define the routes for the application.
24+
*/
25+
public function map(): void
26+
{
27+
$this->mapApiRoutes();
28+
$this->mapWebRoutes();
29+
}
30+
31+
/**
32+
* Define the "web" routes for the application.
33+
*
34+
* These routes all receive session state, CSRF protection, etc.
35+
*/
36+
protected function mapWebRoutes(): void
37+
{
38+
Route::middleware('web')->group(module_path($this->name, '/routes/web.php'));
39+
}
40+
41+
/**
42+
* Define the "api" routes for the application.
43+
*
44+
* These routes are typically stateless.
45+
*/
46+
protected function mapApiRoutes(): void
47+
{
48+
Route::middleware('api')->prefix('api')->name('api.')->group(module_path($this->name, '/routes/api.php'));
49+
}
50+
}
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<?php
2+
3+
namespace Modules\TestingModule\Providers;
4+
5+
use Illuminate\Support\Facades\Blade;
6+
use Illuminate\Support\ServiceProvider;
7+
use Nwidart\Modules\Traits\PathNamespace;
8+
use RecursiveDirectoryIterator;
9+
use RecursiveIteratorIterator;
10+
11+
class TestingModuleServiceProvider extends ServiceProvider
12+
{
13+
use PathNamespace;
14+
15+
protected string $name = 'TestingModule';
16+
17+
protected string $nameLower = 'testingmodule';
18+
19+
/**
20+
* Boot the application events.
21+
*/
22+
public function boot(): void
23+
{
24+
$this->registerCommands();
25+
$this->registerCommandSchedules();
26+
$this->registerTranslations();
27+
$this->registerConfig();
28+
$this->registerViews();
29+
$this->loadMigrationsFrom(module_path($this->name, 'database/migrations'));
30+
}
31+
32+
/**
33+
* Register the service provider.
34+
*/
35+
public function register(): void
36+
{
37+
$this->app->register(EventServiceProvider::class);
38+
$this->app->register(RouteServiceProvider::class);
39+
}
40+
41+
/**
42+
* Register commands in the format of Command::class
43+
*/
44+
protected function registerCommands(): void
45+
{
46+
// $this->commands([]);
47+
}
48+
49+
/**
50+
* Register command Schedules.
51+
*/
52+
protected function registerCommandSchedules(): void
53+
{
54+
// $this->app->booted(function () {
55+
// $schedule = $this->app->make(Schedule::class);
56+
// $schedule->command('inspire')->hourly();
57+
// });
58+
}
59+
60+
/**
61+
* Register translations.
62+
*/
63+
public function registerTranslations(): void
64+
{
65+
$langPath = resource_path('lang/modules/'.$this->nameLower);
66+
67+
if (is_dir($langPath)) {
68+
$this->loadTranslationsFrom($langPath, $this->nameLower);
69+
$this->loadJsonTranslationsFrom($langPath);
70+
} else {
71+
$this->loadTranslationsFrom(module_path($this->name, 'lang'), $this->nameLower);
72+
$this->loadJsonTranslationsFrom(module_path($this->name, 'lang'));
73+
}
74+
}
75+
76+
/**
77+
* Register config.
78+
*/
79+
protected function registerConfig(): void
80+
{
81+
$configPath = module_path($this->name, config('modules.paths.generator.config.path'));
82+
83+
if (is_dir($configPath)) {
84+
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configPath));
85+
86+
foreach ($iterator as $file) {
87+
if ($file->isFile() && $file->getExtension() === 'php') {
88+
$config = str_replace($configPath.DIRECTORY_SEPARATOR, '', $file->getPathname());
89+
$config_key = str_replace([DIRECTORY_SEPARATOR, '.php'], ['.', ''], $config);
90+
$segments = explode('.', $this->nameLower.'.'.$config_key);
91+
92+
// Remove duplicated adjacent segments
93+
$normalized = [];
94+
foreach ($segments as $segment) {
95+
if (end($normalized) !== $segment) {
96+
$normalized[] = $segment;
97+
}
98+
}
99+
100+
$key = ($config === 'config.php') ? $this->nameLower : implode('.', $normalized);
101+
102+
$this->publishes([$file->getPathname() => config_path($config)], 'config');
103+
$this->merge_config_from($file->getPathname(), $key);
104+
}
105+
}
106+
}
107+
}
108+
109+
/**
110+
* Merge config from the given path recursively.
111+
*/
112+
protected function merge_config_from(string $path, string $key): void
113+
{
114+
$existing = config($key, []);
115+
$module_config = require $path;
116+
117+
config([$key => array_replace_recursive($existing, $module_config)]);
118+
}
119+
120+
/**
121+
* Register views.
122+
*/
123+
public function registerViews(): void
124+
{
125+
$viewPath = resource_path('views/modules/'.$this->nameLower);
126+
$sourcePath = module_path($this->name, 'resources/views');
127+
128+
$this->publishes([$sourcePath => $viewPath], ['views', $this->nameLower.'-module-views']);
129+
130+
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower);
131+
132+
Blade::componentNamespace(config('modules.namespace').'\\' . $this->name . '\\View\\Components', $this->nameLower);
133+
}
134+
135+
/**
136+
* Get the services provided by the provider.
137+
*/
138+
public function provides(): array
139+
{
140+
return [];
141+
}
142+
143+
private function getPublishableViewPaths(): array
144+
{
145+
$paths = [];
146+
foreach (config('view.paths') as $path) {
147+
if (is_dir($path.'/modules/'.$this->nameLower)) {
148+
$paths[] = $path.'/modules/'.$this->nameLower;
149+
}
150+
}
151+
152+
return $paths;
153+
}
154+
}

composer.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "nwidart/testingmodule",
3+
"description": "",
4+
"authors": [
5+
{
6+
"name": "Nicolas Widart",
7+
"email": "[email protected]"
8+
}
9+
],
10+
"extra": {
11+
"laravel": {
12+
"providers": [],
13+
"aliases": {
14+
15+
}
16+
}
17+
},
18+
"autoload": {
19+
"psr-4": {
20+
"Modules\\TestingModule\\": "app/",
21+
"Modules\\TestingModule\\Database\\Factories\\": "database/factories/",
22+
"Modules\\TestingModule\\Database\\Seeders\\": "database/seeders/"
23+
}
24+
},
25+
"autoload-dev": {
26+
"psr-4": {
27+
"Modules\\TestingModule\\Tests\\": "tests/"
28+
}
29+
}
30+
}

config/.gitkeep

Whitespace-only changes.

config/config.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return [
4+
'name' => 'TestingModule',
5+
];

0 commit comments

Comments
 (0)