Skip to content
This repository was archived by the owner on Jan 17, 2022. It is now read-only.

Commit dd154da

Browse files
committed
Minor fixes
1 parent 3b58052 commit dd154da

File tree

6 files changed

+41
-27
lines changed

6 files changed

+41
-27
lines changed

src/Generator/ApiMakeCommand.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ protected function setControllerData()
128128
{
129129
$this->stubVariables['controllerName'] = $this->stubVariables['modelName'].'Controller';
130130
$this->stubVariables['controllerName'] = $this->stubVariables['modelName'].'Controller';
131-
$this->stubVariables['controllerNamespace'] = $this->appNamespace.$this->convertSlashes(config('laravel-api-generator.controllers_path'));
131+
$this->stubVariables['controllerNamespace'] = $this->appNamespace.$this->convertSlashes(config('laravel-api-generator.controllers_dir'));
132132
$this->stubVariables['controllerFullName'] = trim($this->stubVariables['controllerNamespace'].'\\'.$this->stubVariables['controllerName'], '\\');
133133

134134
return $this;
@@ -158,7 +158,7 @@ protected function setRouteData()
158158
protected function setTransformerData()
159159
{
160160
$this->stubVariables['transformerName'] = $this->stubVariables['modelName'].'Transformer';
161-
$this->stubVariables['transformerNamespace'] = $this->appNamespace.$this->convertSlashes(config('laravel-api-generator.transformers_path'));
161+
$this->stubVariables['transformerNamespace'] = $this->appNamespace.$this->convertSlashes(config('laravel-api-generator.transformers_dir'));
162162
$this->stubVariables['transformerFullName'] = trim($this->stubVariables['transformerNamespace'].'\\'.$this->stubVariables['transformerName'], '\\');
163163

164164
return $this;
@@ -191,14 +191,14 @@ protected function addRoutes()
191191

192192
// read file
193193
$lines = file($routesFile);
194-
$lastLine = $lines[count($lines) - 1];
194+
$lastLine = trim($lines[count($lines) - 1]);
195195

196196
// modify file
197197
if (strcmp($lastLine, '});') === 0) {
198198
$lines[count($lines) - 1] = ' '.$stub;
199-
$lines[] = "\r\n});";
199+
$lines[] = "\r\n});\r\n";
200200
} else {
201-
$lines[] = "\r\n".$stub;
201+
$lines[] = "$stub\r\n";
202202
}
203203

204204
// save file

src/Generator/stubs/controller.stub

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ class {{controllerName}} extends Controller
2424
{
2525
return new {{transformerName}};
2626
}
27+
2728
}

src/Generator/stubs/transformer.stub

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ class {{transformerName}} extends TransformerAbstract
1414
public function transform({{modelName}} $item)
1515
{
1616
return [
17-
'id' => (int)$item->id,
18-
'created_at' => (string)$item->created_at,
19-
'updated_at' => (string)$item->updated_at,
17+
'id' => (int)$item->id,
18+
'created_at' => (string)$item->created_at,
19+
'updated_at' => (string)$item->updated_at,
2020
];
2121
}
22-
2322
}

src/Skeleton/BaseController.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ public function getStatusCode()
8989
* Setter for statusCode.
9090
*
9191
* @param int $statusCode Value to set
92-
*
9392
* @return self
9493
*/
9594
public function setStatusCode($statusCode)
@@ -104,7 +103,6 @@ public function setStatusCode($statusCode)
104103
*
105104
* @param $item
106105
* @param $callback
107-
*
108106
* @return mixed
109107
*/
110108
protected function respondWithItem($item, $callback)
@@ -121,7 +119,6 @@ protected function respondWithItem($item, $callback)
121119
*
122120
* @param $collection
123121
* @param $callback
124-
*
125122
* @return mixed
126123
*/
127124
protected function respondWithCollection($collection, $callback)
@@ -138,7 +135,6 @@ protected function respondWithCollection($collection, $callback)
138135
*
139136
* @param array $array
140137
* @param array $headers
141-
*
142138
* @return mixed
143139
*/
144140
protected function respondWithArray(array $array, array $headers = [])
@@ -150,7 +146,6 @@ protected function respondWithArray(array $array, array $headers = [])
150146
* Response with the current error.
151147
*
152148
* @param $message
153-
*
154149
* @return mixed
155150
*/
156151
protected function respondWithError($message)
@@ -167,7 +162,6 @@ protected function respondWithError($message)
167162
* Prepare root scope and adds meta.
168163
*
169164
* @param Item $resource
170-
*
171165
* @return mixed
172166
*/
173167
protected function prepareRootScope($resource)
@@ -195,7 +189,6 @@ protected function rulesForCreate()
195189
* Get the validation rules for update.
196190
*
197191
* @param $id
198-
*
199192
* @return array
200193
*/
201194
protected function rulesForUpdate($id)
@@ -219,7 +212,6 @@ public function errorForbidden($message = 'Forbidden')
219212
* Generate a Response with a 500 HTTP header and a given message.
220213
*
221214
* @param $message
222-
*
223215
* @return Response
224216
*/
225217
public function errorInternalError($message = 'Internal Error')
@@ -243,7 +235,6 @@ public function errorNotFound($message = 'Resource Not Found')
243235
* Generate a Response with a 401 HTTP header and a given message.
244236
*
245237
* @param $message
246-
*
247238
* @return Response
248239
*/
249240
public function errorUnauthorized($message = 'Unauthorized')
@@ -255,7 +246,6 @@ public function errorUnauthorized($message = 'Unauthorized')
255246
* Generate a Response with a 400 HTTP header and a given message.
256247
*
257248
* @param $message
258-
*
259249
* @return Response
260250
*/
261251
public function errorWrongArgs($message = 'Wrong Arguments')
@@ -317,7 +307,6 @@ public function store()
317307
* GET /api/{resource}/{id}.
318308
*
319309
* @param int $id
320-
*
321310
* @return Response
322311
*/
323312
public function show($id)
@@ -337,7 +326,6 @@ public function show($id)
337326
* PUT /api/{resource}/{id}.
338327
*
339328
* @param int $id
340-
*
341329
* @return Response
342330
*/
343331
public function update($id)
@@ -372,7 +360,6 @@ public function update($id)
372360
* DELETE /api/{resource}/{id}.
373361
*
374362
* @param int $id
375-
*
376363
* @return Response
377364
*/
378365
public function destroy($id)

src/config/config.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,39 @@
11
<?php
22

33
return [
4-
'controllers_path' => 'Api/Controllers',
5-
'transformers_path' => 'Api/Transformers',
6-
'routes_file' => 'Api/routes.php',
7-
'models_base_dir' => 'Models',
84

5+
/*
6+
* Relative path from the app directory to api controllers directory.
7+
*/
8+
'controllers_dir' => 'Api/Controllers',
9+
10+
/*
11+
* Relative path from the app directory to transformers directory.
12+
*/
13+
'transformers_dir' => 'Api/Transformers',
14+
15+
/*
16+
* Relative path from the app directory to the api routes file.
17+
*/
18+
'routes_file' => 'Api/routes.php',
19+
20+
/*
21+
* Relative path from the app directory to the models directory. Typically it's either 'Models' or ''.
22+
*/
23+
'models_base_dir' => '',
24+
25+
/*
26+
* Relative path from the base directory to the api controller stub.
27+
*/
928
'controller_stub' => 'vendor/arrilot/laravel-api-generator/src/Generator/stubs/controller.stub',
29+
30+
/*
31+
* Relative path from the base directory to the route stub.
32+
*/
1033
'route_stub' => 'vendor/arrilot/laravel-api-generator/src/Generator/stubs/route.stub',
34+
35+
/*
36+
* Relative path from the base directory to the transformer stub.
37+
*/
1138
'transformer_stub' => 'vendor/arrilot/laravel-api-generator/src/Generator/stubs/transformer.stub',
1239
];

templates/Api/routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
22

3-
Route::group(['prefix' => 'api/v1'], function () {
3+
Route::group(['prefix' => 'api/v1', 'namespace' => 'App\Api\Controllers'], function () {
44
//
55
});

0 commit comments

Comments
 (0)