Skip to content

Commit a6c4144

Browse files
authored
Merge pull request #8 from theanik/feature/resolve-namespace-from-config
Feature/resolve namespace from config
2 parents b7d4e8c + 0d1aea9 commit a6c4144

14 files changed

+328
-314
lines changed

README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ Or add the following to your composer.json's require-dev section and `composer u
1919

2020
```json
2121
"require-dev": {
22-
"theanik/laravel-more-command": "^1.2.0"
23-
}
22+
"theanik/laravel-more-command": "^1.3.0"
23+
}
2424
```
2525

2626
## Publish Package Configuration
@@ -31,7 +31,8 @@ Or add the following to your composer.json's require-dev section and `composer u
3131
```php
3232
<?php
3333
return [
34-
'namespace' => 'App', // Your Desire Namespace
34+
'repository-namespace' => 'App', // Your Desire Namespace for Repository Classes
35+
'service-namespace' => 'App', // Your Desire Namespace for Service Classes
3536
];
3637
```
3738

@@ -62,7 +63,7 @@ php artisan make:repository UserRepository
6263
```
6364
or
6465
```
65-
php artisan make:repository Backend\UserRepository
66+
php artisan make:repository Backend/UserRepository
6667
```
6768

6869
The above will create a **Repositories** directory inside the **App** directory.\
@@ -76,7 +77,7 @@ php artisan make:repository UserRepository -i
7677
```
7778
or
7879
```
79-
php artisan make:repository Backend\UserRepository -i
80+
php artisan make:repository Backend/UserRepository -i
8081
```
8182
Here you need to put extra `-i` flag.
8283
The above will create a **Repositories** directory inside the **App** directory.
@@ -93,7 +94,7 @@ php artisan module:make-repository UserRepository Blog
9394
```
9495
or
9596
```
96-
php artisan module:make-repository Backend\UserRepository Blog
97+
php artisan module:make-repository Backend/UserRepository Blog
9798
```
9899

99100
The above will create a **Repositories** directory inside the **{Module}** directory.
@@ -107,7 +108,7 @@ php artisan module:make-repository UserRepository -i Blog
107108
```
108109
or
109110
```
110-
php artisan module:make-repository Backend\UserRepository -i Blog
111+
php artisan module:make-repository Backend/UserRepository -i Blog
111112
```
112113
Here you need to put extra `-i` flag.
113114
The above will create a **Repositories** directory inside the **{Module}** directory.
@@ -145,7 +146,7 @@ php artisan make:service UserService
145146
```
146147
or
147148
```
148-
php artisan make:service Backend\UserService
149+
php artisan make:service Backend/UserService
149150
```
150151
The above will create a **Services** directory inside the **App** directory.
151152

@@ -160,7 +161,7 @@ php artisan module:make-service UserService
160161
```
161162
or
162163
```
163-
php artisan module:make-service Backend\UserService
164+
php artisan module:make-service Backend/UserService
164165
```
165166
The above will create a **Services** directory inside the **{Module}** directory.
166167

@@ -178,7 +179,7 @@ php artisan make:trait HasAuth
178179
```
179180
or
180181
```
181-
php artisan make:trait Backend\HasAuth
182+
php artisan make:trait Backend/HasAuth
182183
```
183184
The above will create a **Traits** directory inside the **App** directory.
184185

@@ -192,7 +193,7 @@ php artisan module:make-trait HasAuth
192193
```
193194
or
194195
```
195-
php artisan module:make-trait Backend\HasAuth
196+
php artisan module:make-trait Backend/HasAuth
196197
```
197198
The above will create a **Traits** directory inside the **{Module}** directory.
198199

@@ -211,7 +212,7 @@ php artisan make:view index
211212
```
212213
or
213214
```
214-
php artisan make:view user\index
215+
php artisan make:view user/index
215216
```
216217
The above will create a **blade** file inside the **/resource/views/** directory.
217218

@@ -225,7 +226,7 @@ php artisan module:make-view index
225226
```
226227
or
227228
```
228-
php artisan module:make-view user\index
229+
php artisan module:make-view user/index
229230
```
230231
The above will create a **blade** file inside the **{Module}/Resources/views/** directory.
231232

config/laravel-more-command.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
<?php
22

3-
43
return [
5-
'namespace' => 'App',
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Repository classes namespace
8+
|--------------------------------------------------------------------------
9+
|
10+
| This value defines the default namespace for created Repository classes.
11+
| For example if the value is 'App/Http', it will create repository classes
12+
| inside 'App/Http/Repositories' and class namespace will
13+
| 'App/Http/Repositories/{ClassName}'.
14+
|
15+
*/
16+
'repository-namespace' => 'App',
17+
18+
/*
19+
|--------------------------------------------------------------------------
20+
| Service classes namespace
21+
|--------------------------------------------------------------------------
22+
|
23+
| This value defines the default namespace for created Service classes.
24+
| For example if the value is 'App/Http', it will create repository classes
25+
| inside 'App/Http/Services' and class namespace will
26+
| 'App/Http/Services/{ClassName}'.
27+
|
28+
*/
29+
'service-namespace' => 'App',
630
];

src/Commands/ClearLogCommand.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,10 @@ public function __construct()
3838
*/
3939
public function handle()
4040
{
41-
4241
exec('rm -f ' . storage_path('logs/*.log'));
43-
42+
4443
$this->info("Logs have been cleared!");
4544

4645
Log::info("Log Cleared at ".date('l jS \of F Y h:i:s A'));
47-
4846
}
4947
}

src/Commands/CommandGenerator.php

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
abstract class CommandGenerator extends Command
88
{
9+
public const APP_PATH = 'App';
910

1011
/**
1112
* argumentName
@@ -20,29 +21,39 @@ abstract class CommandGenerator extends Command
2021
*
2122
* @return string
2223
*/
23-
abstract protected function getTemplateContents();
24+
abstract protected function getTemplateContents(): string;
2425

2526

2627
/**
27-
* Return the destination path for publishe created class file.
28+
* Return the destination path for publish created class file.
2829
* getDestinationFilePath
2930
*
3031
* @return string
3132
*/
32-
abstract protected function getDestinationFilePath();
33+
abstract protected function getDestinationFilePath(): string;
3334

3435

3536
/**
36-
* Get Namespace From Config
37+
* Get Repository Namespace From Config
3738
* @return string
3839
*/
39-
public function getNamespaceFromConfig(): string
40+
public function getRepositoryNamespaceFromConfig(): string
4041
{
41-
return config('laravel-more-command.namespace') ?? 'App';
42+
return config('laravel-more-command.repository-namespace') ?? 'App';
43+
}
44+
45+
46+
/**
47+
* Get Service Namespace From Config
48+
* @return string
49+
*/
50+
public function getServiceNamespaceFromConfig(): string
51+
{
52+
return config('laravel-more-command.service-namespace') ?? 'App';
4253
}
4354

4455
/**
45-
* Return the default namesapce for class
56+
* Return the default namespace for class
4657
* getDefaultNamespace
4758
*
4859
* @return string
@@ -54,7 +65,7 @@ public function getDefaultNamespace(): string
5465

5566

5667
/**
57-
* Return the default namesapce type for interface
68+
* Return the default namespace type for interface
5869
* getDefaultInterfaceNamespace
5970
*
6071
* @return string
@@ -66,28 +77,26 @@ public function getDefaultInterfaceNamespace(): string
6677

6778

6879
/**
69-
* Return a vaid class name
80+
* Return a class name
7081
* getClass
7182
*
72-
* @return void
83+
* @return string
7384
*/
74-
public function getClass()
85+
public function getClass(): string
7586
{
7687
return class_basename($this->argument($this->argumentName));
7788
}
7889

7990

8091
/**
81-
* Generate class namespace dinamacally
92+
* Generate class namespace dynamically
8293
* getClassNamespace
8394
*
84-
* @return void
95+
* @return string
8596
*/
86-
public function getClassNamespace()
97+
public function getClassNamespace(): string
8798
{
88-
$extra = str_replace($this->getClass(), '', $this->argument($this->argumentName));
89-
90-
$extra = str_replace('/', '\\', $extra);
99+
$extra = str_replace(array($this->getClass(), '/'), array('', '\\'), $this->argument($this->argumentName));
91100

92101
$namespace = $this->getDefaultNamespace();
93102

@@ -100,16 +109,14 @@ public function getClassNamespace()
100109

101110

102111
/**
103-
* Generate interface namespace dinamacally
112+
* Generate interface namespace dynamically
104113
* getInterfaceNamespace
105114
*
106-
* @return void
115+
* @return string
107116
*/
108-
public function getInterfaceNamespace()
117+
public function getInterfaceNamespace(): string
109118
{
110-
$extra = str_replace($this->getClass() . 'Interface', '', $this->argument($this->argumentName) . 'Interface');
111-
112-
$extra = str_replace('/', '\\', $extra);
119+
$extra = str_replace(array($this->getClass() . 'Interface', '/'), array('', '\\'), $this->argument($this->argumentName) . 'Interface');
113120

114121
$namespace = $this->getDefaultInterfaceNamespace();
115122

@@ -135,5 +142,4 @@ public function checkModuleExists(string $moduleName): bool
135142
return true;
136143
}
137144

138-
139-
}
145+
}

0 commit comments

Comments
 (0)