@@ -21,7 +21,7 @@ class MakeService extends GeneratorCommand
21
21
*
22
22
* @var string
23
23
*/
24
- protected $ signature = 'make:service {name : Create a service class} {--c : Create a service contract } ' ;
24
+ protected $ signature = 'make:service {name : Create a service class} {--i : Create a service interface } ' ;
25
25
26
26
/**
27
27
* The console command description.
@@ -42,21 +42,24 @@ protected function getStub()
42
42
}
43
43
44
44
/**
45
- * @param bool $isContract
46
45
* @return string
47
46
*/
48
- protected function getServiceStub (bool $ isContract ): string
47
+ protected function getServiceStub (): string
49
48
{
50
- return self ::STUB_PATH .
51
- ($ isContract ? 'service.stub ' : 'service.origin.stub ' );
49
+ return self ::STUB_PATH . 'service.stub ' ;
50
+ }
51
+
52
+ protected function getInterfaceStub (): string
53
+ {
54
+ return self ::STUB_PATH . 'interface.stub ' ;
52
55
}
53
56
54
57
/**
55
58
* @return string
56
59
*/
57
- protected function getServiceContractStub (): string
60
+ protected function getServiceInterfaceStub (): string
58
61
{
59
- return self ::STUB_PATH . 'service.contract .stub ' ;
62
+ return self ::STUB_PATH . 'service.interface .stub ' ;
60
63
}
61
64
62
65
/**
@@ -89,31 +92,31 @@ public function handle()
89
92
}
90
93
91
94
$ this ->makeDirectory ($ path );
92
- $ isContract = $ this ->option ('c ' );
95
+ $ isInterface = $ this ->option ('i ' );
93
96
94
97
$ this ->files ->put (
95
98
$ path ,
96
99
$ this ->sortImports (
97
- $ this ->buildServiceClass ($ name , $ isContract )
100
+ $ this ->buildServiceClass ($ name , $ isInterface )
98
101
)
99
102
);
100
103
$ message = $ this ->type ;
101
104
102
105
// Whether to create contract
103
- if ($ isContract ) {
104
- $ contractName = $ this ->getNameInput () . 'Contract .php ' ;
105
- $ contractPath = str_replace ($ this ->getNameInput () . '.php ' , 'Contracts / ' , $ path );
106
+ if ($ isInterface ) {
107
+ $ interfaceName = $ this ->getNameInput () . 'Interface .php ' ;
108
+ $ interfacePath = str_replace ($ this ->getNameInput () . '.php ' , 'Interfaces / ' , $ path );
106
109
107
- $ this ->makeDirectory ($ contractPath . $ contractName );
110
+ $ this ->makeDirectory ($ interfacePath . $ interfaceName );
108
111
109
112
$ this ->files ->put (
110
- $ contractPath . $ contractName ,
113
+ $ interfacePath . $ interfaceName ,
111
114
$ this ->sortImports (
112
- $ this ->buildServiceContractInterface ($ this ->getNameInput ())
115
+ $ this ->buildServiceInterface ($ this ->getNameInput ())
113
116
)
114
117
);
115
118
116
- $ message .= ' and Contract ' ;
119
+ $ message .= ' and Interface ' ;
117
120
}
118
121
119
122
$ this ->info ($ message . ' created successfully. ' );
@@ -123,14 +126,16 @@ public function handle()
123
126
* Build the class with the given name.
124
127
*
125
128
* @param string $name
126
- * @param $isContract
129
+ * @param $isInterface
127
130
* @return string
128
131
*
129
132
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
130
133
*/
131
- protected function buildServiceClass ($ name , $ isContract ): string
134
+ protected function buildServiceClass (string $ name , $ isInterface ): string
132
135
{
133
- $ stub = $ this ->files ->get ($ this ->getServiceStub ($ isContract ));
136
+ $ stub = $ this ->files ->get (
137
+ $ isInterface ? $ this ->getServiceInterfaceStub () : $ this ->getServiceStub ()
138
+ );
134
139
135
140
return $ this ->replaceNamespace ($ stub , $ name )->replaceClass ($ stub , $ name );
136
141
}
@@ -143,9 +148,9 @@ protected function buildServiceClass($name, $isContract): string
143
148
*
144
149
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
145
150
*/
146
- protected function buildServiceContractInterface ( $ name ): string
151
+ protected function buildServiceInterface ( string $ name ): string
147
152
{
148
- $ stub = $ this ->files ->get ($ this ->getServiceContractStub ());
153
+ $ stub = $ this ->files ->get ($ this ->getInterfaceStub ());
149
154
150
155
return $ this ->replaceNamespace ($ stub , $ name )->replaceClass ($ stub , $ name );
151
156
}
0 commit comments