24
24
use ApiPlatform \State \UriVariablesResolverTrait ;
25
25
use ApiPlatform \State \Util \OperationRequestInitiatorTrait ;
26
26
use ApiPlatform \State \Util \RequestParser ;
27
+ use Psr \Log \LoggerInterface ;
27
28
use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
28
29
29
30
/**
@@ -40,6 +41,7 @@ final class ReadProvider implements ProviderInterface
40
41
public function __construct (
41
42
private readonly ProviderInterface $ provider ,
42
43
private readonly LegacySerializerContextBuilderInterface |SerializerContextBuilderInterface |null $ serializerContextBuilder = null ,
44
+ private readonly ?LoggerInterface $ logger = null ,
43
45
) {
44
46
}
45
47
@@ -63,10 +65,12 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
63
65
$ context ['filters ' ] = $ filters ;
64
66
}
65
67
68
+ $ resourceClass = $ operation ->getClass ();
69
+
66
70
if ($ this ->serializerContextBuilder && $ request ) {
67
71
// Builtin data providers are able to use the serialization context to automatically add join clauses
68
72
$ context += $ normalizationContext = $ this ->serializerContextBuilder ->createFromRequest ($ request , true , [
69
- 'resource_class ' => $ operation -> getClass () ,
73
+ 'resource_class ' => $ resourceClass ,
70
74
'operation ' => $ operation ,
71
75
]);
72
76
$ request ->attributes ->set ('_api_normalization_context ' , $ normalizationContext );
@@ -75,6 +79,8 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
75
79
try {
76
80
$ data = $ this ->provider ->provide ($ operation , $ uriVariables , $ context );
77
81
} 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 ]);
78
84
$ data = null ;
79
85
}
80
86
@@ -85,7 +91,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
85
91
|| ($ operation instanceof Put && !($ operation ->getAllowCreate () ?? false ))
86
92
)
87
93
) {
88
- throw new NotFoundHttpException ('Not Found ' );
94
+ throw new NotFoundHttpException ('Not Found ' , $ e ?? null );
89
95
}
90
96
91
97
$ request ?->attributes->set ('data ' , $ data );
0 commit comments