4
4
5
5
use Blueprint \Blueprint ;
6
6
use Blueprint \Contracts \Generator ;
7
- use Blueprint \Models \Model ;
8
7
use Blueprint \Models \Controller ;
8
+ use Blueprint \Models \Model ;
9
9
use Blueprint \Models \Statements \DispatchStatement ;
10
10
use Blueprint \Models \Statements \EloquentStatement ;
11
11
use Blueprint \Models \Statements \FireStatement ;
@@ -53,7 +53,7 @@ public function output(array $tree): array
53
53
54
54
$ path = $ this ->getPath ($ controller );
55
55
56
- if (!$ this ->files ->exists (dirname ($ path ))) {
56
+ if (! $ this ->files ->exists (dirname ($ path ))) {
57
57
$ this ->files ->makeDirectory (dirname ($ path ), 0755 , true );
58
58
}
59
59
@@ -65,6 +65,11 @@ public function output(array $tree): array
65
65
return $ output ;
66
66
}
67
67
68
+ public function types (): array
69
+ {
70
+ return ['controllers ' ];
71
+ }
72
+
68
73
protected function populateStub (string $ stub , Controller $ controller )
69
74
{
70
75
$ stub = str_replace ('DummyNamespace ' , $ controller ->fullyQualifiedNamespace (), $ stub );
@@ -87,82 +92,82 @@ private function buildMethods(Controller $controller)
87
92
if (in_array ($ name , ['edit ' , 'update ' , 'show ' , 'destroy ' ])) {
88
93
$ context = Str::singular ($ controller ->prefix ());
89
94
$ reference = $ this ->fullyQualifyModelReference ($ controller ->namespace (), Str::camel ($ context ));
90
- $ variable = '$ ' . Str::camel ($ context );
95
+ $ variable = '$ ' . Str::camel ($ context );
91
96
92
97
// TODO: verify controller prefix references a model
93
98
$ search = ' * @return \\Illuminate \\Http \\Response ' ;
94
- $ method = str_replace ($ search , ' * @param \\' . $ reference . ' ' . $ variable . PHP_EOL . $ search , $ method );
99
+ $ method = str_replace ($ search , ' * @param \\' . $ reference. ' ' . $ variable. PHP_EOL . $ search , $ method );
95
100
96
101
$ search = '(Request $request ' ;
97
- $ method = str_replace ($ search , $ search . ', ' . $ context . ' ' . $ variable , $ method );
102
+ $ method = str_replace ($ search , $ search. ', ' . $ context. ' ' . $ variable , $ method );
98
103
$ this ->addImport ($ controller , $ reference );
99
104
}
100
105
101
106
$ body = '' ;
102
107
foreach ($ statements as $ statement ) {
103
108
if ($ statement instanceof SendStatement) {
104
- $ body .= self ::INDENT . $ statement ->output () . PHP_EOL ;
109
+ $ body .= self ::INDENT . $ statement ->output (). PHP_EOL ;
105
110
if ($ statement ->type () === SendStatement::TYPE_NOTIFICATION_WITH_FACADE ) {
106
111
$ this ->addImport ($ controller , 'Illuminate \\Support \\Facades \\Notification ' );
107
- $ this ->addImport ($ controller , config ('blueprint.namespace ' ) . '\\Notification \\' . $ statement ->mail ());
112
+ $ this ->addImport ($ controller , config ('blueprint.namespace ' ). '\\Notification \\' . $ statement ->mail ());
108
113
} elseif ($ statement ->type () === SendStatement::TYPE_MAIL ) {
109
114
$ this ->addImport ($ controller , 'Illuminate \\Support \\Facades \\Mail ' );
110
- $ this ->addImport ($ controller , config ('blueprint.namespace ' ) . '\\Mail \\' . $ statement ->mail ());
115
+ $ this ->addImport ($ controller , config ('blueprint.namespace ' ). '\\Mail \\' . $ statement ->mail ());
111
116
}
112
117
} elseif ($ statement instanceof ValidateStatement) {
113
- $ class_name = $ controller ->name () . Str::studly ($ name ) . 'Request ' ;
118
+ $ class_name = $ controller ->name (). Str::studly ($ name ). 'Request ' ;
114
119
115
- $ fqcn = config ('blueprint.namespace ' ) . '\\Http \\Requests \\' . ($ controller ->namespace () ? $ controller ->namespace () . '\\' : '' ) . $ class_name ;
120
+ $ fqcn = config ('blueprint.namespace ' ). '\\Http \\Requests \\' . ($ controller ->namespace () ? $ controller ->namespace (). '\\' : '' ). $ class_name ;
116
121
117
- $ method = str_replace ('\Illuminate\Http\Request $request ' , '\\' . $ fqcn . ' $request ' , $ method );
118
- $ method = str_replace ('(Request $request ' , '( ' . $ class_name . ' $request ' , $ method );
122
+ $ method = str_replace ('\Illuminate\Http\Request $request ' , '\\' . $ fqcn. ' $request ' , $ method );
123
+ $ method = str_replace ('(Request $request ' , '( ' . $ class_name. ' $request ' , $ method );
119
124
120
125
$ this ->addImport ($ controller , $ fqcn );
121
126
} elseif ($ statement instanceof DispatchStatement) {
122
- $ body .= self ::INDENT . $ statement ->output () . PHP_EOL ;
123
- $ this ->addImport ($ controller , config ('blueprint.namespace ' ) . '\\Jobs \\' . $ statement ->job ());
127
+ $ body .= self ::INDENT . $ statement ->output (). PHP_EOL ;
128
+ $ this ->addImport ($ controller , config ('blueprint.namespace ' ). '\\Jobs \\' . $ statement ->job ());
124
129
} elseif ($ statement instanceof FireStatement) {
125
- $ body .= self ::INDENT . $ statement ->output () . PHP_EOL ;
126
- if (!$ statement ->isNamedEvent ()) {
127
- $ this ->addImport ($ controller , config ('blueprint.namespace ' ) . '\\Events \\' . $ statement ->event ());
130
+ $ body .= self ::INDENT . $ statement ->output (). PHP_EOL ;
131
+ if (! $ statement ->isNamedEvent ()) {
132
+ $ this ->addImport ($ controller , config ('blueprint.namespace ' ). '\\Events \\' . $ statement ->event ());
128
133
}
129
134
} elseif ($ statement instanceof RenderStatement) {
130
- $ body .= self ::INDENT . $ statement ->output () . PHP_EOL ;
135
+ $ body .= self ::INDENT . $ statement ->output (). PHP_EOL ;
131
136
} elseif ($ statement instanceof ResourceStatement) {
132
- $ fqcn = config ('blueprint.namespace ' ) . '\\Http \\Resources \\' . ($ controller ->namespace () ? $ controller ->namespace () . '\\' : '' ) . $ statement ->name ();
137
+ $ fqcn = config ('blueprint.namespace ' ). '\\Http \\Resources \\' . ($ controller ->namespace () ? $ controller ->namespace (). '\\' : '' ). $ statement ->name ();
133
138
134
- $ method = str_replace ('* @return \\Illuminate \\Http \\Response ' , '* @return \\' . $ fqcn , $ method );
139
+ $ method = str_replace ('* @return \\Illuminate \\Http \\Response ' , '* @return \\' . $ fqcn , $ method );
135
140
136
141
$ import = $ fqcn ;
137
- if (!$ statement ->collection ()) {
138
- $ import .= ' as ' . $ statement ->name () . 'Resource ' ;
142
+ if (! $ statement ->collection ()) {
143
+ $ import .= ' as ' . $ statement ->name (). 'Resource ' ;
139
144
}
140
145
141
146
$ this ->addImport ($ controller , $ import );
142
147
143
- $ body .= self ::INDENT . $ statement ->output () . PHP_EOL ;
148
+ $ body .= self ::INDENT . $ statement ->output (). PHP_EOL ;
144
149
} elseif ($ statement instanceof RedirectStatement) {
145
- $ body .= self ::INDENT . $ statement ->output () . PHP_EOL ;
150
+ $ body .= self ::INDENT . $ statement ->output (). PHP_EOL ;
146
151
} elseif ($ statement instanceof RespondStatement) {
147
- $ body .= self ::INDENT . $ statement ->output () . PHP_EOL ;
152
+ $ body .= self ::INDENT . $ statement ->output (). PHP_EOL ;
148
153
} elseif ($ statement instanceof SessionStatement) {
149
- $ body .= self ::INDENT . $ statement ->output () . PHP_EOL ;
154
+ $ body .= self ::INDENT . $ statement ->output (). PHP_EOL ;
150
155
} elseif ($ statement instanceof EloquentStatement) {
151
- $ body .= self ::INDENT . $ statement ->output ($ controller ->prefix (), $ name ) . PHP_EOL ;
156
+ $ body .= self ::INDENT . $ statement ->output ($ controller ->prefix (), $ name ). PHP_EOL ;
152
157
$ this ->addImport ($ controller , $ this ->determineModel ($ controller , $ statement ->reference ()));
153
158
} elseif ($ statement instanceof QueryStatement) {
154
- $ body .= self ::INDENT . $ statement ->output ($ controller ->prefix ()) . PHP_EOL ;
159
+ $ body .= self ::INDENT . $ statement ->output ($ controller ->prefix ()). PHP_EOL ;
155
160
$ this ->addImport ($ controller , $ this ->determineModel ($ controller , $ statement ->model ()));
156
161
}
157
162
158
163
$ body .= PHP_EOL ;
159
164
}
160
165
161
- if (!empty ($ body )) {
166
+ if (! empty ($ body )) {
162
167
$ method = str_replace ('// ' , trim ($ body ), $ method );
163
168
}
164
169
165
- $ methods .= PHP_EOL . $ method ;
170
+ $ methods .= PHP_EOL . $ method ;
166
171
}
167
172
168
173
return trim ($ methods );
@@ -172,7 +177,7 @@ protected function getPath(Controller $controller)
172
177
{
173
178
$ path = str_replace ('\\' , '/ ' , Blueprint::relativeNamespace ($ controller ->fullyQualifiedClassName ()));
174
179
175
- return Blueprint::appPath () . '/ ' . $ path . '.php ' ;
180
+ return Blueprint::appPath (). '/ ' . $ path. '.php ' ;
176
181
}
177
182
178
183
private function addImport (Controller $ controller , $ class )
@@ -186,7 +191,7 @@ private function buildImports(Controller $controller)
186
191
sort ($ imports );
187
192
188
193
return implode (PHP_EOL , array_map (function ($ class ) {
189
- return 'use ' . $ class . '; ' ;
194
+ return 'use ' . $ class. '; ' ;
190
195
}, $ imports ));
191
196
}
192
197
@@ -216,7 +221,7 @@ private function fullyQualifyModelReference(string $sub_namespace, string $model
216
221
return $ model ->fullyQualifiedClassName ();
217
222
}
218
223
219
- return config ('blueprint.namespace ' ) . '\\' . ($ sub_namespace ? $ sub_namespace . '\\' : '' ) . $ model_name ;
224
+ return config ('blueprint.namespace ' ). '\\' . ($ sub_namespace ? $ sub_namespace. '\\' : '' ). $ model_name ;
220
225
}
221
226
222
227
private function modelForContext (string $ context )
0 commit comments