Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

Commit d5929c8

Browse files
committed
Modification: changed the src path to app in generated modules
- Generate modules with the app path instead of src path - Deprecated srcPath in the Module helper class
1 parent 276f279 commit d5929c8

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

config/modular.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
'namespace' => 'Modules',
77
'vendor' => 'modular',
88
'directory_tree' => [
9+
'app',
10+
'app/Console',
11+
'app/Console/Commands',
12+
'app/Http',
13+
'app/Http/Controllers',
14+
'app/Models',
15+
'app/Providers',
916
'bootstrap',
1017
'bootstrap/cache',
1118
'config',
@@ -20,18 +27,6 @@
2027
'resources/js',
2128
'resources/css',
2229
'routes',
23-
'src',
24-
'src/Console',
25-
'src/Console/Commands',
26-
'src/Exceptions',
27-
'src/Facades',
28-
'src/Http',
29-
'src/Http/Controllers',
30-
'src/Models',
31-
'src/Policies',
32-
'src/Providers',
33-
'src/Support/Concerns',
34-
'src/Support/Contracts',
3530
'storage',
3631
'tests',
3732
],

src/Commands/ModuleMakeCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Support\Str;
88
use Psr\Container\ContainerExceptionInterface;
99
use Psr\Container\NotFoundExceptionInterface;
10+
use Savannabits\Modular\Facades\Modular;
1011
use Savannabits\Modular\Support\Concerns\CanManipulateFiles;
1112

1213
use function Laravel\Prompts\text;
@@ -86,7 +87,7 @@ private function generateModuleComposerFile(): void
8687
],
8788
'autoload' => [
8889
'psr-4' => [
89-
$this->moduleNamespace.'\\' => 'src/',
90+
$this->moduleNamespace.'\\' => 'app/',
9091
$this->moduleNamespace.'\\Database\\Factories\\' => 'database/factories/',
9192
$this->moduleNamespace.'\\Database\\Seeders\\' => 'database/seeders/',
9293
],
@@ -123,7 +124,7 @@ private function generateModuleComposerFile(): void
123124
*/
124125
private function generateModuleServiceProvider(): void
125126
{
126-
$path = $this->modulePath.'/src/'.$this->moduleStudlyName.'ServiceProvider.php';
127+
$path = Modular::module($this->moduleName)->appPath($this->moduleStudlyName.'ServiceProvider.php');
127128
$namespace = $this->moduleNamespace;
128129
$class = $this->moduleStudlyName.'ServiceProvider';
129130
$this->copyStubToApp('module.provider', $path, [

src/Module.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,17 @@ public function factoriesPath(string $path = '', bool $relative = false): string
102102
return $this->databasePath('factories'.DIRECTORY_SEPARATOR.trim($path, DIRECTORY_SEPARATOR), $relative);
103103
}
104104

105+
/**
106+
* @deprecated Use appPath instead
107+
*/
105108
public function srcPath(string $path = '', bool $relative = false): string
106109
{
107-
return $this->path('src'.DIRECTORY_SEPARATOR.trim($path, DIRECTORY_SEPARATOR), $relative);
110+
return $this->appPath($path, $relative);
111+
}
112+
113+
public function appPath(string $path = '', bool $relative = false): string
114+
{
115+
return $this->path('app'.DIRECTORY_SEPARATOR.trim($path, DIRECTORY_SEPARATOR), $relative);
108116
}
109117

110118
public function resourcePath(string $string, bool $relative = false): string

src/Support/Concerns/GeneratesModularFiles.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ protected function getPath($name): string
5353
{
5454
$name = Str::replaceFirst($this->rootNamespace(), '', $name);
5555

56-
return $this->getModule()->srcPath(str_replace('\\', '/', $name).'.php');
56+
return $this->getModule()->appPath(str_replace('\\', '/', $name).'.php');
5757
}
5858

5959
protected function possibleModels()
6060
{
61-
$modelPath = $this->getModule()->srcPath('Models');
61+
$modelPath = $this->getModule()->appPath('Models');
6262

6363
return collect(Finder::create()->files()->depth(0)->in($modelPath))
6464
->map(fn ($file) => $file->getBasename('.php'))

0 commit comments

Comments
 (0)