Skip to content

Commit b7d4e8c

Browse files
authored
Merge pull request #7 from ShakilAhmmed/master
Implemented Namespace Resolve From Config File
2 parents 4951574 + 9c56bdb commit b7d4e8c

8 files changed

+118
-87
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor
2+
.idea/

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ Or add the following to your composer.json's require-dev section and `composer u
2222
"theanik/laravel-more-command": "^1.2.0"
2323
}
2424
```
25+
26+
## Publish Package Configuration
27+
```shell
28+
php artisan vendor:publish --provider="Theanik\LaravelMoreCommand\LaravelMoreCommandProvider" --tag="config"
29+
```
30+
### To Change Default Namespace [config/laravel-more-command.php]
31+
```php
32+
<?php
33+
return [
34+
'namespace' => 'App', // Your Desire Namespace
35+
];
36+
```
37+
2538
## Artisan Command List
2639

2740
<!-- List Of Command -->

config/laravel-more-command.php

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

src/Commands/CommandGenerator.php

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,24 @@
44

55
use Illuminate\Console\Command;
66

7-
abstract class CommandGenerator extends Command{
8-
7+
abstract class CommandGenerator extends Command
8+
{
9+
910
/**
1011
* argumentName
1112
*
1213
* @var mixed
1314
*/
1415
public $argumentName;
15-
16+
1617
/**
1718
* Return the rendered File Content
1819
* getTemplateContents
1920
*
2021
* @return string
2122
*/
2223
abstract protected function getTemplateContents();
23-
24+
2425

2526
/**
2627
* Return the destination path for publishe created class file.
@@ -29,32 +30,41 @@ abstract protected function getTemplateContents();
2930
* @return string
3031
*/
3132
abstract protected function getDestinationFilePath();
32-
33+
34+
35+
/**
36+
* Get Namespace From Config
37+
* @return string
38+
*/
39+
public function getNamespaceFromConfig(): string
40+
{
41+
return config('laravel-more-command.namespace') ?? 'App';
42+
}
3343

3444
/**
3545
* Return the default namesapce for class
3646
* getDefaultNamespace
3747
*
3848
* @return string
3949
*/
40-
public function getDefaultNamespace() : string
50+
public function getDefaultNamespace(): string
4151
{
4252
return '';
4353
}
4454

45-
55+
4656
/**
4757
* Return the default namesapce type for interface
4858
* getDefaultInterfaceNamespace
4959
*
5060
* @return string
5161
*/
52-
public function getDefaultInterfaceNamespace() : string
62+
public function getDefaultInterfaceNamespace(): string
5363
{
5464
return '';
5565
}
5666

57-
67+
5868
/**
5969
* Return a vaid class name
6070
* getClass
@@ -66,7 +76,7 @@ public function getClass()
6676
return class_basename($this->argument($this->argumentName));
6777
}
6878

69-
79+
7080
/**
7181
* Generate class namespace dinamacally
7282
* getClassNamespace
@@ -79,7 +89,7 @@ public function getClassNamespace()
7989

8090
$extra = str_replace('/', '\\', $extra);
8191

82-
$namespace = $this->getDefaultNamespace();
92+
$namespace = $this->getDefaultNamespace();
8393

8494
$namespace .= '\\' . $extra;
8595

@@ -89,7 +99,6 @@ public function getClassNamespace()
8999
}
90100

91101

92-
93102
/**
94103
* Generate interface namespace dinamacally
95104
* getInterfaceNamespace
@@ -98,11 +107,11 @@ public function getClassNamespace()
98107
*/
99108
public function getInterfaceNamespace()
100109
{
101-
$extra = str_replace($this->getClass().'Interface', '', $this->argument($this->argumentName).'Interface');
110+
$extra = str_replace($this->getClass() . 'Interface', '', $this->argument($this->argumentName) . 'Interface');
102111

103112
$extra = str_replace('/', '\\', $extra);
104113

105-
$namespace = $this->getDefaultInterfaceNamespace();
114+
$namespace = $this->getDefaultInterfaceNamespace();
106115

107116
$namespace .= '\\' . $extra;
108117

@@ -112,22 +121,19 @@ public function getInterfaceNamespace()
112121
}
113122

114123

115-
116124
/**
117125
* checkModuleExists
118126
*
119-
* @param mixed $moduleName
127+
* @param mixed $moduleName
120128
* @return bool
121129
*/
122-
public function checkModuleExists(string $moduleName):bool
130+
public function checkModuleExists(string $moduleName): bool
123131
{
124-
if (!in_array($moduleName,scandir(base_path()."/Modules"))) {
132+
if (!in_array($moduleName, scandir(base_path() . "/Modules"))) {
125133
return false;
126134
}
127135
return true;
128136
}
129137

130138

131-
132-
133139
}

0 commit comments

Comments
 (0)