2424use ApiPlatform \State \UriVariablesResolverTrait ;
2525use ApiPlatform \State \Util \OperationRequestInitiatorTrait ;
2626use ApiPlatform \State \Util \RequestParser ;
27+ use Psr \Log \LoggerInterface ;
2728use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
2829
2930/**
@@ -40,6 +41,7 @@ final class ReadProvider implements ProviderInterface
4041 public function __construct (
4142 private readonly ProviderInterface $ provider ,
4243 private readonly LegacySerializerContextBuilderInterface |SerializerContextBuilderInterface |null $ serializerContextBuilder = null ,
44+ private readonly ?LoggerInterface $ logger = null ,
4345 ) {
4446 }
4547
@@ -63,10 +65,12 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
6365 $ context ['filters ' ] = $ filters ;
6466 }
6567
68+ $ resourceClass = $ operation ->getClass ();
69+
6670 if ($ this ->serializerContextBuilder && $ request ) {
6771 // Builtin data providers are able to use the serialization context to automatically add join clauses
6872 $ context += $ normalizationContext = $ this ->serializerContextBuilder ->createFromRequest ($ request , true , [
69- 'resource_class ' => $ operation -> getClass () ,
73+ 'resource_class ' => $ resourceClass ,
7074 'operation ' => $ operation ,
7175 ]);
7276 $ request ->attributes ->set ('_api_normalization_context ' , $ normalizationContext );
@@ -75,6 +79,8 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
7579 try {
7680 $ data = $ this ->provider ->provide ($ operation , $ uriVariables , $ context );
7781 } catch (ProviderNotFoundException $ e ) {
82+ // In case the dev just forgot to implement it
83+ $ this ->logger ?->debug('No provider registered for {resource_class} ' , ['resource_class ' => $ resourceClass ]);
7884 $ data = null ;
7985 }
8086
@@ -85,7 +91,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
8591 || ($ operation instanceof Put && !($ operation ->getAllowCreate () ?? false ))
8692 )
8793 ) {
88- throw new NotFoundHttpException ('Not Found ' );
94+ throw new NotFoundHttpException ('Not Found ' , $ e ?? null );
8995 }
9096
9197 $ request ?->attributes->set ('data ' , $ data );
0 commit comments