1 | <?php |
||
42 | class ResponderServiceProvider extends BaseServiceProvider |
||
43 | { |
||
44 | /** |
||
45 | * Indicates if loading of the provider is deferred. |
||
46 | * |
||
47 | * @var bool |
||
48 | */ |
||
49 | protected $defer = false; |
||
50 | |||
51 | /** |
||
52 | * Register the service provider. |
||
53 | * |
||
54 | * @return void |
||
55 | */ |
||
56 | 192 | public function register() |
|
73 | |||
74 | /** |
||
75 | * Register Laravel bindings. |
||
76 | * |
||
77 | * @return void |
||
78 | */ |
||
79 | 192 | protected function registerLaravelBindings() |
|
85 | |||
86 | /** |
||
87 | * Register Lumen bindings. |
||
88 | * |
||
89 | * @return void |
||
90 | */ |
||
91 | protected function registerLumenBindings() |
||
92 | { |
||
93 | $this->app->singleton(ResponseFactoryContract::class, function ($app) { |
||
94 | return $this->decorateResponseFactory($app->make(LumenResponseFactory::class)); |
||
95 | }); |
||
96 | |||
97 | $this->app->bind(Translator::class, function ($app) { |
||
98 | return $app['translator']; |
||
99 | }); |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Decorate response factories. |
||
104 | * |
||
105 | * @param \Flugg\Responder\Contracts\ResponseFactory $factory |
||
106 | * @return \Flugg\Responder\Contracts\ResponseFactory |
||
107 | */ |
||
108 | 55 | protected function decorateResponseFactory(ResponseFactoryContract $factory): ResponseFactory |
|
116 | |||
117 | /** |
||
118 | * Register serializer bindings. |
||
119 | * |
||
120 | * @return void |
||
121 | */ |
||
122 | 192 | protected function registerSerializerBindings() |
|
123 | { |
||
124 | $this->app->bind(ErrorSerializerContract::class, function ($app) { |
||
125 | 55 | return $app->make($app->config['responder.serializers.error']); |
|
126 | 192 | }); |
|
127 | |||
128 | $this->app->bind(SerializerAbstract::class, function ($app) { |
||
129 | 55 | return $app->make($app->config['responder.serializers.success']); |
|
130 | 192 | }); |
|
131 | 192 | } |
|
132 | |||
133 | /** |
||
134 | * Register error bindings. |
||
135 | * |
||
136 | * @return void |
||
137 | */ |
||
138 | 192 | protected function registerErrorBindings() |
|
139 | { |
||
140 | $this->app->singleton(ErrorMessageResolverContract::class, function ($app) { |
||
141 | 55 | return $app->make(ErrorMessageResolver::class); |
|
142 | 192 | }); |
|
143 | |||
144 | $this->app->singleton(ErrorFactoryContract::class, function ($app) { |
||
145 | 55 | return $app->make(ErrorFactory::class); |
|
146 | 192 | }); |
|
147 | |||
148 | $this->app->bind(ErrorResponseBuilder::class, function ($app) { |
||
149 | 55 | return (new ErrorResponseBuilder($app->make(ResponseFactoryContract::class), $app->make(ErrorFactoryContract::class)))->serializer($app->make(ErrorSerializerContract::class)); |
|
150 | 192 | }); |
|
151 | 192 | } |
|
152 | |||
153 | /** |
||
154 | * Register Fractal bindings. |
||
155 | * |
||
156 | * @return void |
||
157 | */ |
||
158 | 192 | protected function registerFractalBindings() |
|
164 | |||
165 | /** |
||
166 | * Register transformer bindings. |
||
167 | * |
||
168 | * @return void |
||
169 | */ |
||
170 | 192 | protected function registerTransformerBindings() |
|
171 | { |
||
172 | $this->app->singleton(TransformerResolverContract::class, function ($app) { |
||
173 | 57 | return new TransformerResolver($app, $app->config['responder.fallback_transformer']); |
|
174 | 192 | }); |
|
175 | |||
176 | BaseTransformer::containerResolver(function () { |
||
177 | 22 | return $this->app->make(Container::class); |
|
178 | 192 | }); |
|
179 | 192 | } |
|
180 | |||
181 | /** |
||
182 | * Register pagination bindings. |
||
183 | * |
||
184 | * @return void |
||
185 | */ |
||
186 | 192 | protected function registerResourceBindings() |
|
187 | { |
||
188 | $this->app->singleton(ResourceKeyResolverContract::class, function ($app) { |
||
189 | 57 | return $app->make(ResourceKeyResolver::class); |
|
190 | 192 | }); |
|
191 | |||
192 | $this->app->singleton(ResourceFactoryContract::class, function ($app) { |
||
193 | 57 | return $app->make(ResourceFactory::class); |
|
194 | 192 | }); |
|
195 | 192 | } |
|
196 | |||
197 | /** |
||
198 | * Register pagination bindings. |
||
199 | * |
||
200 | * @return void |
||
201 | */ |
||
202 | 192 | protected function registerPaginationBindings() |
|
208 | |||
209 | /** |
||
210 | * Register transformation bindings. |
||
211 | * |
||
212 | * @return void |
||
213 | */ |
||
214 | 192 | protected function registerTransformationBindings() |
|
215 | { |
||
216 | $this->app->bind(TransformFactoryContract::class, function ($app) { |
||
217 | 55 | return $app->make(FractalTransformFactory::class); |
|
218 | 192 | }); |
|
219 | |||
220 | $this->app->bind(TransformBuilder::class, function ($app) { |
||
221 | 55 | $request = $this->app->make(Request::class); |
|
222 | 55 | $relations = $request->input($this->app->config['responder.load_relations_parameter'], []); |
|
223 | 55 | $fieldsets = $request->input($app->config['responder.filter_fields_parameter'], []); |
|
224 | |||
225 | 55 | return (new TransformBuilder($app->make(ResourceFactoryContract::class), $app->make(TransformFactoryContract::class), $app->make(PaginatorFactoryContract::class)))->serializer($app->make(SerializerAbstract::class)) |
|
226 | 55 | ->with(is_string($relations) ? explode(',', $relations) : $relations) |
|
227 | 55 | ->only($fieldsets); |
|
228 | 192 | }); |
|
229 | 192 | } |
|
230 | |||
231 | /** |
||
232 | * Register service bindings. |
||
233 | * |
||
234 | * @return void |
||
235 | */ |
||
236 | 192 | protected function registerServiceBindings() |
|
242 | |||
243 | /** |
||
244 | * Bootstrap the application events. |
||
245 | * |
||
246 | * @return void |
||
247 | */ |
||
248 | 192 | public function boot() |
|
259 | |||
260 | /** |
||
261 | * Bootstrap the Laravel application. |
||
262 | * |
||
263 | * @return void |
||
264 | */ |
||
265 | 192 | protected function bootLaravelApplication() |
|
276 | |||
277 | /** |
||
278 | * Bootstrap the Lumen application. |
||
279 | * |
||
280 | * @return void |
||
281 | */ |
||
282 | protected function bootLumenApplication() |
||
286 | } |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.