|
86 | 86 | use ApiPlatform\Laravel\Eloquent\Metadata\ModelMetadata; |
87 | 87 | use ApiPlatform\Laravel\Eloquent\Metadata\ResourceClassResolver as EloquentResourceClassResolver; |
88 | 88 | use ApiPlatform\Laravel\Eloquent\PropertyAccess\PropertyAccessor as EloquentPropertyAccessor; |
| 89 | +use ApiPlatform\Laravel\Eloquent\PropertyInfo\EloquentExtractor; |
| 90 | +use ApiPlatform\Laravel\Eloquent\Serializer\EloquentNameConverter; |
89 | 91 | use ApiPlatform\Laravel\Eloquent\Serializer\SerializerContextBuilder as EloquentSerializerContextBuilder; |
90 | 92 | use ApiPlatform\Laravel\GraphQl\Controller\EntrypointController as GraphQlEntrypointController; |
91 | 93 | use ApiPlatform\Laravel\GraphQl\Controller\GraphiQlController; |
@@ -195,15 +197,16 @@ public function register(): void |
195 | 197 | { |
196 | 198 | $this->mergeConfigFrom(__DIR__.'/config/api-platform.php', 'api-platform'); |
197 | 199 |
|
198 | | - $this->app->singleton(PropertyInfoExtractorInterface::class, function () { |
| 200 | + $this->app->singleton(PropertyInfoExtractorInterface::class, function (Application $app) { |
199 | 201 | $phpstanExtractor = class_exists(PhpDocParser::class) ? new PhpStanExtractor() : null; |
200 | 202 | $reflectionExtractor = new ReflectionExtractor(); |
| 203 | + $eloquentExtractor = new EloquentExtractor($app->make(ModelMetadata::class)); |
201 | 204 |
|
202 | 205 | return new PropertyInfoExtractor( |
203 | 206 | [$reflectionExtractor], |
204 | 207 | $phpstanExtractor ? [$phpstanExtractor, $reflectionExtractor] : [$reflectionExtractor], |
205 | 208 | [], |
206 | | - [$reflectionExtractor], |
| 209 | + [$eloquentExtractor], |
207 | 210 | [$reflectionExtractor] |
208 | 211 | ); |
209 | 212 | }); |
@@ -262,10 +265,10 @@ public function register(): void |
262 | 265 | return new CachePropertyMetadataFactory( |
263 | 266 | new SchemaPropertyMetadataFactory( |
264 | 267 | $app->make(ResourceClassResolverInterface::class), |
265 | | - new PropertyInfoPropertyMetadataFactory( |
266 | | - $app->make(PropertyInfoExtractorInterface::class), |
267 | | - new SerializerPropertyMetadataFactory( |
268 | | - $app->make(SerializerClassMetadataFactory::class), |
| 268 | + new SerializerPropertyMetadataFactory( |
| 269 | + $app->make(SerializerClassMetadataFactory::class), |
| 270 | + new PropertyInfoPropertyMetadataFactory( |
| 271 | + $app->make(PropertyInfoExtractorInterface::class), |
269 | 272 | new AttributePropertyMetadataFactory( |
270 | 273 | new EloquentAttributePropertyMetadataFactory( |
271 | 274 | new EloquentPropertyMetadataFactory( |
@@ -315,7 +318,7 @@ public function register(): void |
315 | 318 | $config = $app['config']; |
316 | 319 | $nameConverter = $config->get('api-platform.name_converter', SnakeCaseToCamelCaseNameConverter::class); |
317 | 320 | if ($nameConverter && class_exists($nameConverter)) { |
318 | | - $nameConverter = $app->make($nameConverter); |
| 321 | + $nameConverter = new EloquentNameConverter($app->make($nameConverter)); |
319 | 322 | } |
320 | 323 |
|
321 | 324 | $defaultContext = $config->get('api-platform.serializer', []); |
@@ -400,9 +403,13 @@ public function register(): void |
400 | 403 | }); |
401 | 404 | $this->app->bind(SerializerContextBuilderInterface::class, EloquentSerializerContextBuilder::class); |
402 | 405 | $this->app->singleton(EloquentSerializerContextBuilder::class, function (Application $app) { |
| 406 | + /** @var ConfigRepository */ |
| 407 | + $config = $app['config']; |
| 408 | + |
403 | 409 | return new EloquentSerializerContextBuilder( |
404 | 410 | $app->make(SerializerContextBuilder::class), |
405 | | - $app->make(PropertyNameCollectionFactoryInterface::class) |
| 411 | + $app->make(PropertyNameCollectionFactoryInterface::class), |
| 412 | + $config->get('api-platform.name_converter', SnakeCaseToCamelCaseNameConverter::class) |
406 | 413 | ); |
407 | 414 | }); |
408 | 415 |
|
|
0 commit comments