@@ -12,69 +12,69 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | return [ |
| 15 | - /* |
|
| 15 | + /* |
|
| 16 | 16 | |----------------------------------------------------------------------------------------------------------- |
| 17 | 17 | | Code range settings |
| 18 | 18 | |----------------------------------------------------------------------------------------------------------- |
| 19 | 19 | */ |
| 20 | - 'min_code' => 100, |
|
| 21 | - 'max_code' => 1024, |
|
| 20 | + 'min_code' => 100, |
|
| 21 | + 'max_code' => 1024, |
|
| 22 | 22 | |
| 23 | - /* |
|
| 23 | + /* |
|
| 24 | 24 | |----------------------------------------------------------------------------------------------------------- |
| 25 | 25 | | Error code to message mapping |
| 26 | 26 | |----------------------------------------------------------------------------------------------------------- |
| 27 | 27 | | |
| 28 | 28 | */ |
| 29 | - 'map' => [ |
|
| 29 | + 'map' => [ |
|
| 30 | 30 | |
| 31 | - ], |
|
| 31 | + ], |
|
| 32 | 32 | |
| 33 | - /* |
|
| 33 | + /* |
|
| 34 | 34 | |----------------------------------------------------------------------------------------------------------- |
| 35 | 35 | | Response Builder classes |
| 36 | 36 | |----------------------------------------------------------------------------------------------------------- |
| 37 | 37 | | |
| 38 | 38 | */ |
| 39 | - 'classes' => [ |
|
| 40 | - \Illuminate\Database\Eloquent\Model::class => [ |
|
| 41 | - 'key' => 'item', |
|
| 42 | - 'method' => 'toArray', |
|
| 43 | - 'pri' => 0, |
|
| 44 | - ], |
|
| 45 | - \Illuminate\Support\Collection::class => [ |
|
| 46 | - 'key' => 'items', |
|
| 47 | - 'method' => 'toArray', |
|
| 48 | - 'pri' => -1, |
|
| 49 | - ], |
|
| 50 | - \Illuminate\Database\Eloquent\Collection::class => [ |
|
| 51 | - 'key' => 'items', |
|
| 52 | - 'method' => 'toArray', |
|
| 53 | - 'pri' => 0, |
|
| 54 | - ], |
|
| 55 | - \Illuminate\Http\Resources\Json\JsonResource::class => [ |
|
| 56 | - 'key' => 'item', |
|
| 57 | - 'method' => 'toArray', |
|
| 58 | - 'pri' => 0, |
|
| 59 | - ], |
|
| 60 | - ], |
|
| 39 | + 'classes' => [ |
|
| 40 | + \Illuminate\Database\Eloquent\Model::class => [ |
|
| 41 | + 'key' => 'item', |
|
| 42 | + 'method' => 'toArray', |
|
| 43 | + 'pri' => 0, |
|
| 44 | + ], |
|
| 45 | + \Illuminate\Support\Collection::class => [ |
|
| 46 | + 'key' => 'items', |
|
| 47 | + 'method' => 'toArray', |
|
| 48 | + 'pri' => -1, |
|
| 49 | + ], |
|
| 50 | + \Illuminate\Database\Eloquent\Collection::class => [ |
|
| 51 | + 'key' => 'items', |
|
| 52 | + 'method' => 'toArray', |
|
| 53 | + 'pri' => 0, |
|
| 54 | + ], |
|
| 55 | + \Illuminate\Http\Resources\Json\JsonResource::class => [ |
|
| 56 | + 'key' => 'item', |
|
| 57 | + 'method' => 'toArray', |
|
| 58 | + 'pri' => 0, |
|
| 59 | + ], |
|
| 60 | + ], |
|
| 61 | 61 | |
| 62 | - /* |
|
| 62 | + /* |
|
| 63 | 63 | |----------------------------------------------------------------------------------------------------------- |
| 64 | 64 | | data-to-json encoding options |
| 65 | 65 | |----------------------------------------------------------------------------------------------------------- |
| 66 | 66 | | |
| 67 | 67 | */ |
| 68 | - 'encoding_options' => JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE, |
|
| 68 | + 'encoding_options' => JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE, |
|
| 69 | 69 | |
| 70 | - /* |
|
| 70 | + /* |
|
| 71 | 71 | |----------------------------------------------------------------------------------------------------------- |
| 72 | 72 | | Exception handler error codes |
| 73 | 73 | |----------------------------------------------------------------------------------------------------------- |
| 74 | 74 | | |
| 75 | 75 | */ |
| 76 | - 'exception_handler' => [ |
|
| 77 | - 'exception' => [ |
|
| 76 | + 'exception_handler' => [ |
|
| 77 | + 'exception' => [ |
|
| 78 | 78 | // 'http_not_found' => [ |
| 79 | 79 | // 'code' => \App\ApiCodes::HTTP_NOT_FOUND(), |
| 80 | 80 | // 'http_code' => Symfony\Component\HttpFoundation\Response::HTTP_BAD_REQUEST, |
@@ -99,21 +99,21 @@ discard block |
||
| 99 | 99 | // 'code' => \App\ApiCodes::VALIDATION_EXCEPTION(), |
| 100 | 100 | // 'http_code' => Symfony\Component\HttpFoundation\Response::HTTP_UNPROCESSABLE_ENTITY, |
| 101 | 101 | // ], |
| 102 | - ], |
|
| 103 | - ], |
|
| 102 | + ], |
|
| 103 | + ], |
|
| 104 | 104 | |
| 105 | - /* |
|
| 105 | + /* |
|
| 106 | 106 | |----------------------------------------------------------------------------------------------------------- |
| 107 | 107 | | Debug config |
| 108 | 108 | |----------------------------------------------------------------------------------------------------------- |
| 109 | 109 | | |
| 110 | 110 | */ |
| 111 | - 'debug' => [ |
|
| 112 | - 'debug_key' => 'debug', |
|
| 113 | - 'exception_handler' => [ |
|
| 114 | - 'trace_key' => 'trace', |
|
| 115 | - 'trace_enabled' => env('APP_DEBUG', false), |
|
| 116 | - ], |
|
| 117 | - ], |
|
| 111 | + 'debug' => [ |
|
| 112 | + 'debug_key' => 'debug', |
|
| 113 | + 'exception_handler' => [ |
|
| 114 | + 'trace_key' => 'trace', |
|
| 115 | + 'trace_enabled' => env('APP_DEBUG', false), |
|
| 116 | + ], |
|
| 117 | + ], |
|
| 118 | 118 | |
| 119 | 119 | ]; |
@@ -25,50 +25,50 @@ |
||
| 25 | 25 | |
| 26 | 26 | class ResponseBuilderServiceProvider extends ServiceProvider |
| 27 | 27 | { |
| 28 | - /** |
|
| 29 | - * Register bindings in the container. |
|
| 30 | - * |
|
| 31 | - * @return void |
|
| 32 | - */ |
|
| 33 | - public function register() |
|
| 34 | - { |
|
| 35 | - $this->mergeConfigFrom( |
|
| 36 | - __DIR__ . '/../config/response_builder.php', 'response_builder' |
|
| 37 | - ); |
|
| 38 | - } |
|
| 28 | + /** |
|
| 29 | + * Register bindings in the container. |
|
| 30 | + * |
|
| 31 | + * @return void |
|
| 32 | + */ |
|
| 33 | + public function register() |
|
| 34 | + { |
|
| 35 | + $this->mergeConfigFrom( |
|
| 36 | + __DIR__ . '/../config/response_builder.php', 'response_builder' |
|
| 37 | + ); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Sets up package resources |
|
| 42 | - * |
|
| 43 | - * @return void |
|
| 44 | - */ |
|
| 45 | - public function boot() |
|
| 46 | - { |
|
| 47 | - $this->loadTranslationsFrom(__DIR__ . '/lang', 'response-builder'); |
|
| 40 | + /** |
|
| 41 | + * Sets up package resources |
|
| 42 | + * |
|
| 43 | + * @return void |
|
| 44 | + */ |
|
| 45 | + public function boot() |
|
| 46 | + { |
|
| 47 | + $this->loadTranslationsFrom(__DIR__ . '/lang', 'response-builder'); |
|
| 48 | 48 | |
| 49 | - $source = __DIR__ . '/../config/response_builder.php'; |
|
| 50 | - $this->publishes([ |
|
| 51 | - $source => config_path('response_builder.php'), |
|
| 52 | - ]); |
|
| 53 | - } |
|
| 49 | + $source = __DIR__ . '/../config/response_builder.php'; |
|
| 50 | + $this->publishes([ |
|
| 51 | + $source => config_path('response_builder.php'), |
|
| 52 | + ]); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Merge the given configuration with the existing configuration. |
|
| 57 | - * |
|
| 58 | - * @param string $path |
|
| 59 | - * @param string $key |
|
| 60 | - * |
|
| 61 | - * @return void |
|
| 62 | - */ |
|
| 63 | - protected function mergeConfigFrom($path, $key) |
|
| 64 | - { |
|
| 65 | - $defaults = require $path; |
|
| 66 | - $config = $this->app['config']->get($key, []); |
|
| 55 | + /** |
|
| 56 | + * Merge the given configuration with the existing configuration. |
|
| 57 | + * |
|
| 58 | + * @param string $path |
|
| 59 | + * @param string $key |
|
| 60 | + * |
|
| 61 | + * @return void |
|
| 62 | + */ |
|
| 63 | + protected function mergeConfigFrom($path, $key) |
|
| 64 | + { |
|
| 65 | + $defaults = require $path; |
|
| 66 | + $config = $this->app['config']->get($key, []); |
|
| 67 | 67 | |
| 68 | - $merged_config = Util::mergeConfig($defaults, $config); |
|
| 69 | - Util::sortArrayByPri($merged_config['classes']); |
|
| 68 | + $merged_config = Util::mergeConfig($defaults, $config); |
|
| 69 | + Util::sortArrayByPri($merged_config['classes']); |
|
| 70 | 70 | |
| 71 | - $this->app['config']->set($key, $merged_config); |
|
| 72 | - } |
|
| 71 | + $this->app['config']->set($key, $merged_config); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | 74 | } |