@@ -5,11 +5,11 @@ |
||
5 | 5 | "path" => "storage/mock", // Default folder path of the mock api |
6 | 6 | "paginate" => true, // Define if we must paginate the results or not |
7 | 7 | "per_page" => 10, // Define the number of items per page (if paginate = true) |
8 | - "condition" => function(){ // The condition to define if the mock routing is enabled or not |
|
8 | + "condition" => function() { // The condition to define if the mock routing is enabled or not |
|
9 | 9 | return app()->isLocal(); |
10 | 10 | }, |
11 | 11 | "force_json" => true, // Force the whole mock controller to render application/json |
12 | - "entrypoints" => [ // instead of looking into a folder you can also run a factory($class$, $number$)->states($state$)->make($override$) or add validation on controller method |
|
12 | + "entrypoints" => [// instead of looking into a folder you can also run a factory($class$, $number$)->states($state$)->make($override$) or add validation on controller method |
|
13 | 13 | /*"users" => [ |
14 | 14 | "class" => \App\User::class, // if null factory won't be triggerred |
15 | 15 | "number" => 100, // number of factory to run |
@@ -22,7 +22,7 @@ |
||
22 | 22 | 'mock' |
23 | 23 | ); |
24 | 24 | |
25 | - $this->app->bind('mock', function () { |
|
25 | + $this->app->bind('mock', function() { |
|
26 | 26 | return new Mock(); |
27 | 27 | }); |
28 | 28 |
@@ -2,9 +2,9 @@ |
||
2 | 2 | |
3 | 3 | namespace Blok\Mock; |
4 | 4 | |
5 | -class Mock{ |
|
5 | +class Mock { |
|
6 | 6 | |
7 | - public static function getPath(){ |
|
7 | + public static function getPath() { |
|
8 | 8 | return config("mock.path"); |
9 | 9 | } |
10 | 10 |
@@ -150,7 +150,7 @@ |
||
150 | 150 | $data = $request->all(); |
151 | 151 | $data['id'] = uniqid(); |
152 | 152 | |
153 | - \File::put($folder . '/' . $data['id'] . '.json', json_encode($data)); |
|
153 | + \File::put($folder . '/' . $data['id'] . '.json', json_encode($data)); |
|
154 | 154 | |
155 | 155 | return $data; |
156 | 156 | } |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | * @param $request Request |
28 | 28 | * @throws \Illuminate\Validation\ValidationException |
29 | 29 | */ |
30 | - public function _handleValidation($table, $method, $request){ |
|
30 | + public function _handleValidation($table, $method, $request) { |
|
31 | 31 | |
32 | - $validation = config("mock.entrypoints.".$table.".".$method."_validation"); |
|
32 | + $validation = config("mock.entrypoints." . $table . "." . $method . "_validation"); |
|
33 | 33 | |
34 | - if (config("mock.force_json") || config("mock.entrypoints.".$table.".".$method."_force_json")) { |
|
34 | + if (config("mock.force_json") || config("mock.entrypoints." . $table . "." . $method . "_force_json")) { |
|
35 | 35 | $request->server->set('HTTP_ACCEPT', 'application/json'); |
36 | 36 | $request->headers = new HeaderBag($request->server->getHeaders()); |
37 | 37 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | { |
61 | 61 | $this->_handleValidation($table, "index", $request); |
62 | 62 | |
63 | - $entity = config("mock.entrypoints.".$table); |
|
63 | + $entity = config("mock.entrypoints." . $table); |
|
64 | 64 | |
65 | 65 | if ($entity) { |
66 | 66 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | $data = factory($entity["class"], $entity["number"])->states($entity["states"])->make($entity["override"]); |
71 | 71 | |
72 | - $data = $data->map(function ($item, $key) { |
|
72 | + $data = $data->map(function($item, $key) { |
|
73 | 73 | |
74 | 74 | if (!$item["id"]) { |
75 | 75 | $item['id'] = $key + 1; |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | $currentPageItems = $itemCollection->slice(($currentPage * $perPage) - $perPage, $perPage)->values()->all(); |
121 | 121 | |
122 | 122 | // Create our paginator and pass it to the view |
123 | - $paginatedItems= new LengthAwarePaginator($currentPageItems , count($itemCollection), $perPage); |
|
123 | + $paginatedItems = new LengthAwarePaginator($currentPageItems, count($itemCollection), $perPage); |
|
124 | 124 | |
125 | 125 | // set url path for generted links |
126 | 126 | $paginatedItems->setPath($request->url()); |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | { |
167 | 167 | $this->_handleValidation($table, "update", $request); |
168 | 168 | |
169 | - $folder = public_path(Mock::getPath() ."/". $table); |
|
169 | + $folder = public_path(Mock::getPath() . "/" . $table); |
|
170 | 170 | |
171 | 171 | if (!is_dir($folder)) { |
172 | 172 | \File::makeDirectory($folder, 493, true); |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | { |
195 | 195 | $this->_handleValidation($table, "view", $request); |
196 | 196 | |
197 | - $entity = config("mock.entrypoints.".$table); |
|
197 | + $entity = config("mock.entrypoints." . $table); |
|
198 | 198 | |
199 | 199 | if ($entity) { |
200 | 200 |
@@ -2,13 +2,13 @@ |
||
2 | 2 | |
3 | 3 | use Blok\Mock\Mock; |
4 | 4 | |
5 | -if(Mock::meetEnvCondition()){ |
|
6 | - Route::group(["namespace" => "Blok\\Mock\\Http\\Controllers"], function(){ |
|
7 | - Route::post(config("mock.route").'/{table}', 'MockController@store'); |
|
8 | - Route::any(config("mock.route").'/{table}/create', 'MockController@store'); |
|
9 | - Route::get(config("mock.route").'/{table}', 'MockController@index'); |
|
10 | - Route::any(config("mock.route").'/{table}/{id}/update', 'MockController@update'); |
|
11 | - Route::put(config("mock.route").'/{table}/{id}', 'MockController@update'); |
|
12 | - Route::get(config("mock.route").'/{table}/{id}', 'MockController@view'); |
|
5 | +if (Mock::meetEnvCondition()) { |
|
6 | + Route::group(["namespace" => "Blok\\Mock\\Http\\Controllers"], function() { |
|
7 | + Route::post(config("mock.route") . '/{table}', 'MockController@store'); |
|
8 | + Route::any(config("mock.route") . '/{table}/create', 'MockController@store'); |
|
9 | + Route::get(config("mock.route") . '/{table}', 'MockController@index'); |
|
10 | + Route::any(config("mock.route") . '/{table}/{id}/update', 'MockController@update'); |
|
11 | + Route::put(config("mock.route") . '/{table}/{id}', 'MockController@update'); |
|
12 | + Route::get(config("mock.route") . '/{table}/{id}', 'MockController@view'); |
|
13 | 13 | }); |
14 | 14 | } |
15 | 15 | \ No newline at end of file |