Skip to content
This repository was archived by the owner on Feb 18, 2024. It is now read-only.

Commit 20ec19f

Browse files
author
atehnix
committed
Added customizable module prefix for namespaces
1 parent d4fcd92 commit 20ec19f

20 files changed

+118
-26
lines changed

publish/config/stubs.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,16 @@
3535
'rule' => '\Rules',
3636
],
3737

38+
/*
39+
|--------------------------------------------------------------------------
40+
| The name of the module that is being developed
41+
|--------------------------------------------------------------------------
42+
| When specified, the namespaces will be prefixed with
43+
| the appropriate module name.
44+
|
45+
| For example, if the module is set to 'Blog', then the namespace
46+
| for the controllers might look like: "App\Blog\Http\Controllers"
47+
*/
48+
'module' => env('STUBS_MODULE', ''),
49+
3850
];

src/Console/ChannelMakeCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
class ChannelMakeCommand extends BaseChannelMakeCommand
1616
{
17+
use Modulable;
18+
1719
/**
1820
* Get the stub file for the generator.
1921
*
@@ -34,6 +36,6 @@ protected function getStub()
3436
*/
3537
protected function getDefaultNamespace($rootNamespace)
3638
{
37-
return $rootNamespace . config('stubs.namespaces.channel');
39+
return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.channel');
3840
}
3941
}

src/Console/ConsoleMakeCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
class ConsoleMakeCommand extends BaseConsoleMakeCommand
1616
{
17+
use Modulable;
18+
1719
/**
1820
* Get the stub file for the generator.
1921
*
@@ -34,6 +36,6 @@ protected function getStub()
3436
*/
3537
protected function getDefaultNamespace($rootNamespace)
3638
{
37-
return $rootNamespace . config('stubs.namespaces.command');
39+
return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.command');
3840
}
3941
}

src/Console/ControllerMakeCommand.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
class ControllerMakeCommand extends BaseControllerMakeCommand
1818
{
19+
use Modulable;
20+
1921
/**
2022
* The Laravel application instance.
2123
*
@@ -61,7 +63,7 @@ protected function getStub()
6163
*/
6264
protected function getDefaultNamespace($rootNamespace)
6365
{
64-
return $rootNamespace . config('stubs.namespaces.controller');
66+
return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.controller');
6567
}
6668

6769
/**
@@ -77,7 +79,11 @@ protected function parseModel($model)
7779
}
7880

7981
$model = trim(str_replace('/', '\\', $model), '\\');
80-
$namespace = $this->laravel->getNamespace() . ltrim(config('stubs.namespaces.model') . '\\', '\\');
82+
83+
$namespace =
84+
trim($this->laravel->getNamespace(), '\\')
85+
. $this->getModuleNamespace()
86+
. config('stubs.namespaces.model') . '\\';
8187

8288
if (!Str::startsWith($model, $namespace)) {
8389
$model = $namespace . $model;

src/Console/EventMakeCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
class EventMakeCommand extends BaseEventMakeCommand
1616
{
17+
use Modulable;
18+
1719
/**
1820
* Get the stub file for the generator.
1921
*
@@ -34,6 +36,6 @@ protected function getStub()
3436
*/
3537
protected function getDefaultNamespace($rootNamespace)
3638
{
37-
return $rootNamespace . config('stubs.namespaces.event');
39+
return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.event');
3840
}
3941
}

src/Console/ExceptionMakeCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
class ExceptionMakeCommand extends BaseExceptionMakeCommand
1616
{
17+
use Modulable;
18+
1719
/**
1820
* Get the stub file for the generator.
1921
*
@@ -42,6 +44,6 @@ protected function getStub()
4244
*/
4345
protected function getDefaultNamespace($rootNamespace)
4446
{
45-
return $rootNamespace . config('stubs.namespaces.exception');
47+
return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.exception');
4648
}
4749
}

src/Console/FactoryMakeCommand.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
class FactoryMakeCommand extends BaseFactoryMakeCommand
1717
{
18+
use Modulable;
19+
1820
/**
1921
* The Laravel application instance.
2022
*
@@ -52,7 +54,11 @@ protected function buildClass($name)
5254
protected function parseModel($model)
5355
{
5456
$model = trim(str_replace('/', '\\', $model), '\\');
55-
$namespace = $this->laravel->getNamespace() . ltrim(config('stubs.namespaces.model') . '\\', '\\');
57+
58+
$namespace =
59+
trim($this->laravel->getNamespace(), '\\')
60+
. $this->getModuleNamespace()
61+
. config('stubs.namespaces.model') . '\\';
5662

5763
if (!Str::startsWith($model, $namespace)) {
5864
$model = $namespace . $model;

src/Console/JobMakeCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
class JobMakeCommand extends BaseJobMakeCommand
1616
{
17+
use Modulable;
18+
1719
/**
1820
* Get the stub file for the generator.
1921
*
@@ -38,6 +40,6 @@ protected function getStub()
3840
*/
3941
protected function getDefaultNamespace($rootNamespace)
4042
{
41-
return $rootNamespace . config('stubs.namespaces.job');
43+
return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.job');
4244
}
4345
}

src/Console/ListenerMakeCommand.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
class ListenerMakeCommand extends BaseListenerMakeCommand
1717
{
18+
use Modulable;
19+
1820
/**
1921
* The Laravel application instance.
2022
*
@@ -30,7 +32,7 @@ class ListenerMakeCommand extends BaseListenerMakeCommand
3032
*/
3133
protected function getDefaultNamespace($rootNamespace)
3234
{
33-
return $rootNamespace . config('stubs.namespaces.listener');
35+
return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.listener');
3436
}
3537

3638
/**
@@ -73,13 +75,17 @@ protected function getEvent()
7375
{
7476
$event = $this->option('event');
7577

78+
$namespace =
79+
trim($this->laravel->getNamespace(), '\\')
80+
. $this->getModuleNamespace()
81+
. config('stubs.namespaces.event') . '\\';
82+
7683
if (!Str::startsWith($event, [
77-
$this->laravel->getNamespace(),
84+
$namespace,
7885
'Illuminate',
7986
'\\',
8087
])) {
81-
$eventNamespace = ltrim(config('stubs.namespaces.event'), '\\') . '\\';
82-
$event = $this->laravel->getNamespace() . $eventNamespace . $event;
88+
$event = $namespace . $event;
8389
}
8490

8591
return $event;

src/Console/MailMakeCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
class MailMakeCommand extends BaseMailMakeCommand
1616
{
17+
use Modulable;
18+
1719
/**
1820
* Get the stub file for the generator.
1921
*
@@ -38,6 +40,6 @@ protected function getStub()
3840
*/
3941
protected function getDefaultNamespace($rootNamespace)
4042
{
41-
return $rootNamespace . config('stubs.namespaces.mail');
43+
return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.mail');
4244
}
4345
}

0 commit comments

Comments
 (0)