@@ -43,18 +43,18 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function boot() |
45 | 45 | { |
46 | - if ($this->app instanceof Laravel && $this->app->runningInConsole()) { |
|
46 | + if ( $this->app instanceof Laravel && $this->app->runningInConsole() ) { |
|
47 | 47 | $this->bootLaravelApplication(); |
48 | 48 | |
49 | - } elseif ($this->app instanceof Lumen) { |
|
49 | + } elseif ( $this->app instanceof Lumen ) { |
|
50 | 50 | $this->bootLumenApplication(); |
51 | 51 | } |
52 | 52 | |
53 | - $this->mergeConfigFrom(__DIR__ . '/../resources/config/responder.php', 'responder'); |
|
53 | + $this->mergeConfigFrom( __DIR__ . '/../resources/config/responder.php', 'responder' ); |
|
54 | 54 | |
55 | - $this->commands([ |
|
55 | + $this->commands( [ |
|
56 | 56 | MakeTransformer::class |
57 | - ]); |
|
57 | + ] ); |
|
58 | 58 | |
59 | 59 | include __DIR__ . '/helpers.php'; |
60 | 60 | } |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | $this->registerFractal(); |
70 | 70 | $this->registerResponseBuilders(); |
71 | 71 | |
72 | - $this->app->bind(Responder::class, function ($app) { |
|
73 | - return new Responder($app[SuccessResponseBuilder::class], $app[ErrorResponseBuilder::class]); |
|
72 | + $this->app->bind( Responder::class, function ( $app ) { |
|
73 | + return new Responder( $app[ SuccessResponseBuilder::class ], $app[ ErrorResponseBuilder::class ] ); |
|
74 | 74 | }); |
75 | 75 | |
76 | 76 | $this->registerAliases(); |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public function provides() |
85 | 85 | { |
86 | - return ['responder', 'responder.success', 'responder.error', 'responder.manager', 'responder.serializer']; |
|
86 | + return [ 'responder', 'responder.success', 'responder.error', 'responder.manager', 'responder.serializer' ]; |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -94,17 +94,17 @@ discard block |
||
94 | 94 | */ |
95 | 95 | protected function registerFractal() |
96 | 96 | { |
97 | - $this->app->bind(SerializerAbstract::class, function ($app) { |
|
98 | - $serializer = $app->config->get('responder.serializer'); |
|
97 | + $this->app->bind( SerializerAbstract::class, function ( $app ) { |
|
98 | + $serializer = $app->config->get( 'responder.serializer' ); |
|
99 | 99 | |
100 | 100 | return new $serializer; |
101 | 101 | }); |
102 | 102 | |
103 | - $this->app->bind(Manager::class, function ($app) { |
|
104 | - return (new Manager())->setSerializer($app[SerializerAbstract::class]); |
|
103 | + $this->app->bind( Manager::class, function ( $app ) { |
|
104 | + return (new Manager())->setSerializer( $app[ SerializerAbstract::class ] ); |
|
105 | 105 | }); |
106 | 106 | |
107 | - $this->app->bind(ResourceFactory::class, function () { |
|
107 | + $this->app->bind( ResourceFactory::class, function () { |
|
108 | 108 | return new ResourceFactory(); |
109 | 109 | }); |
110 | 110 | } |
@@ -116,20 +116,20 @@ discard block |
||
116 | 116 | */ |
117 | 117 | protected function registerResponseBuilders() |
118 | 118 | { |
119 | - $this->app->bind(SuccessResponseBuilder::class, function ($app) { |
|
120 | - $builder = new SuccessResponseBuilder(response(), $app[ResourceFactory::class], $app[Manager::class]); |
|
119 | + $this->app->bind( SuccessResponseBuilder::class, function ( $app ) { |
|
120 | + $builder = new SuccessResponseBuilder( response(), $app[ ResourceFactory::class ], $app[ Manager::class ] ); |
|
121 | 121 | |
122 | - if ($parameter = $this->app->config->get('responder.includeFromParameter')) { |
|
123 | - $builder->include($this->app[Request::class]->input($parameter, [])); |
|
122 | + if ( $parameter = $this->app->config->get( 'responder.includeFromParameter' ) ) { |
|
123 | + $builder->include( $this->app[ Request::class ]->input( $parameter, [ ] ) ); |
|
124 | 124 | } |
125 | 125 | |
126 | - return $builder->setIncludeStatusCode($app->config->get('responder.include_status_code')); |
|
126 | + return $builder->setIncludeStatusCode( $app->config->get( 'responder.include_status_code' ) ); |
|
127 | 127 | }); |
128 | 128 | |
129 | - $this->app->bind(ErrorResponseBuilder::class, function ($app) { |
|
130 | - $builder = new ErrorResponseBuilder(response(), $app['translator']); |
|
129 | + $this->app->bind( ErrorResponseBuilder::class, function ( $app ) { |
|
130 | + $builder = new ErrorResponseBuilder( response(), $app[ 'translator' ] ); |
|
131 | 131 | |
132 | - return $builder->setIncludeStatusCode($app->config->get('responder.include_status_code')); |
|
132 | + return $builder->setIncludeStatusCode( $app->config->get( 'responder.include_status_code' ) ); |
|
133 | 133 | }); |
134 | 134 | } |
135 | 135 | |
@@ -140,11 +140,11 @@ discard block |
||
140 | 140 | */ |
141 | 141 | protected function registerAliases() |
142 | 142 | { |
143 | - $this->app->alias(Responder::class, 'responder'); |
|
144 | - $this->app->alias(SuccessResponseBuilder::class, 'responder.success'); |
|
145 | - $this->app->alias(ErrorResponseBuilder::class, 'responder.error'); |
|
146 | - $this->app->alias(Manager::class, 'responder.manager'); |
|
147 | - $this->app->alias(Manager::class, 'responder.serializer'); |
|
143 | + $this->app->alias( Responder::class, 'responder' ); |
|
144 | + $this->app->alias( SuccessResponseBuilder::class, 'responder.success' ); |
|
145 | + $this->app->alias( ErrorResponseBuilder::class, 'responder.error' ); |
|
146 | + $this->app->alias( Manager::class, 'responder.manager' ); |
|
147 | + $this->app->alias( Manager::class, 'responder.serializer' ); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -154,13 +154,13 @@ discard block |
||
154 | 154 | */ |
155 | 155 | protected function bootLaravelApplication() |
156 | 156 | { |
157 | - $this->publishes([ |
|
158 | - __DIR__ . '/../resources/config/responder.php' => config_path('responder.php') |
|
159 | - ], 'config'); |
|
157 | + $this->publishes( [ |
|
158 | + __DIR__ . '/../resources/config/responder.php' => config_path( 'responder.php' ) |
|
159 | + ], 'config' ); |
|
160 | 160 | |
161 | - $this->publishes([ |
|
162 | - __DIR__ . '/../resources/lang/en/errors.php' => app_path('resources/lang/en/errors.php') |
|
163 | - ], 'lang'); |
|
161 | + $this->publishes( [ |
|
162 | + __DIR__ . '/../resources/lang/en/errors.php' => app_path( 'resources/lang/en/errors.php' ) |
|
163 | + ], 'lang' ); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -170,6 +170,6 @@ discard block |
||
170 | 170 | */ |
171 | 171 | protected function bootLumenApplication() |
172 | 172 | { |
173 | - $this->app->configure('responder'); |
|
173 | + $this->app->configure( 'responder' ); |
|
174 | 174 | } |
175 | 175 | } |
176 | 176 | \ No newline at end of file |
@@ -32,12 +32,12 @@ discard block |
||
32 | 32 | * @param Exception $exception |
33 | 33 | * @return void |
34 | 34 | */ |
35 | - protected function transformException(Exception $exception) |
|
35 | + protected function transformException( Exception $exception ) |
|
36 | 36 | { |
37 | - if (Request::capture()->wantsJson()) { |
|
38 | - $this->transformAuthException($exception); |
|
39 | - $this->transformEloquentException($exception); |
|
40 | - $this->transformValidationException($exception); |
|
37 | + if ( Request::capture()->wantsJson() ) { |
|
38 | + $this->transformAuthException( $exception ); |
|
39 | + $this->transformEloquentException( $exception ); |
|
40 | + $this->transformValidationException( $exception ); |
|
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
@@ -49,13 +49,13 @@ discard block |
||
49 | 49 | * @throws UnauthenticatedException |
50 | 50 | * @throws UnauthorizedException |
51 | 51 | */ |
52 | - protected function transformAuthException(Exception $exception) |
|
52 | + protected function transformAuthException( Exception $exception ) |
|
53 | 53 | { |
54 | - if ($exception instanceof AuthenticationException) { |
|
54 | + if ( $exception instanceof AuthenticationException ) { |
|
55 | 55 | throw new UnauthenticatedException(); |
56 | 56 | } |
57 | 57 | |
58 | - if ($exception instanceof AuthorizationException) { |
|
58 | + if ( $exception instanceof AuthorizationException ) { |
|
59 | 59 | throw new UnauthorizedException(); |
60 | 60 | } |
61 | 61 | } |
@@ -68,13 +68,13 @@ discard block |
||
68 | 68 | * @throws ResourceNotFoundException |
69 | 69 | * @throws RelationNotFoundException |
70 | 70 | */ |
71 | - protected function transformEloquentException(Exception $exception) |
|
71 | + protected function transformEloquentException( Exception $exception ) |
|
72 | 72 | { |
73 | - if ($exception instanceof ModelNotFoundException) { |
|
73 | + if ( $exception instanceof ModelNotFoundException ) { |
|
74 | 74 | throw new ResourceNotFoundException(); |
75 | 75 | } |
76 | 76 | |
77 | - if ($exception instanceof RelationNotFoundException) { |
|
77 | + if ( $exception instanceof RelationNotFoundException ) { |
|
78 | 78 | throw new RelationNotFoundException(); |
79 | 79 | } |
80 | 80 | } |
@@ -86,10 +86,10 @@ discard block |
||
86 | 86 | * @return void |
87 | 87 | * @throws ValidationFailedException |
88 | 88 | */ |
89 | - protected function transformValidationException(Exception $exception) |
|
89 | + protected function transformValidationException( Exception $exception ) |
|
90 | 90 | { |
91 | - if ($exception instanceof ValidationException) { |
|
92 | - throw new ValidationFailedException($exception->validator); |
|
91 | + if ( $exception instanceof ValidationException ) { |
|
92 | + throw new ValidationFailedException( $exception->validator ); |
|
93 | 93 | } |
94 | 94 | } |
95 | 95 | |
@@ -99,11 +99,11 @@ discard block |
||
99 | 99 | * @param ApiException $exception |
100 | 100 | * @return JsonResponse |
101 | 101 | */ |
102 | - protected function renderApiError(ApiException $exception):JsonResponse |
|
102 | + protected function renderApiError( ApiException $exception ):JsonResponse |
|
103 | 103 | { |
104 | - return app('responder.error') |
|
105 | - ->setError($exception->getErrorCode(), $exception->getMessage()) |
|
106 | - ->addData($exception->getData() ?: []) |
|
107 | - ->respond($exception->getStatusCode()); |
|
104 | + return app( 'responder.error' ) |
|
105 | + ->setError( $exception->getErrorCode(), $exception->getMessage() ) |
|
106 | + ->addData( $exception->getData() ?: [ ] ) |
|
107 | + ->respond( $exception->getStatusCode() ); |
|
108 | 108 | } |
109 | 109 | } |
110 | 110 | \ No newline at end of file |