29
29
*/
30
30
final class LinkedDataPlatformProcessor implements ProcessorInterface
31
31
{
32
- private const DEFAULT_ALLOWED_METHOD = ['OPTIONS ' , 'HEAD ' ];
32
+ private const DEFAULT_ALLOWED_METHODS = ['OPTIONS ' , 'HEAD ' ];
33
33
34
34
/**
35
35
* @param ProcessorInterface<T1, T2> $decorated
36
36
*/
37
37
public function __construct (
38
- private readonly ProcessorInterface $ decorated , // todo is processor interface nullable
38
+ private readonly ProcessorInterface $ decorated ,
39
39
private readonly ?ResourceClassResolverInterface $ resourceClassResolver = null ,
40
- private readonly ?ResourceMetadataCollectionFactoryInterface $ resourceCollectionMetadataFactory = null ,
40
+ private readonly ?ResourceMetadataCollectionFactoryInterface $ resourceMetadataCollectionFactory = null ,
41
41
) {
42
42
}
43
43
@@ -48,22 +48,21 @@ public function process(mixed $data, Operation $operation, array $uriVariables =
48
48
!$ response instanceof Response
49
49
|| !$ operation instanceof HttpOperation
50
50
|| $ operation instanceof Error
51
- || null === $ this ->resourceCollectionMetadataFactory
51
+ || ! $ this ->resourceMetadataCollectionFactory
52
52
|| !($ context ['resource_class ' ] ?? null )
53
- || null === $ operation ->getUriTemplate ()
53
+ || ! $ operation ->getUriTemplate ()
54
54
|| !$ this ->resourceClassResolver ?->isResourceClass($ context ['resource_class ' ])
55
55
) {
56
56
return $ response ;
57
57
}
58
58
59
- $ allowedMethods = self ::DEFAULT_ALLOWED_METHOD ;
60
- $ resourceMetadataCollection = $ this ->resourceCollectionMetadataFactory ->create ($ context ['resource_class ' ]);
61
- foreach ($ resourceMetadataCollection as $ resource ) {
62
- foreach ($ resource ->getOperations () as $ resourceOperation ) {
63
- if ($ resourceOperation ->getUriTemplate () === $ operation ->getUriTemplate ()) {
64
- $ operationMethod = $ resourceOperation ->getMethod ();
65
- $ allowedMethods [] = $ operationMethod ;
66
- if ('POST ' === $ operationMethod && \is_array ($ outputFormats = $ operation ->getOutputFormats ())) {
59
+ $ allowedMethods = self ::DEFAULT_ALLOWED_METHODS ;
60
+ $ resourceCollection = $ this ->resourceMetadataCollectionFactory ->create ($ context ['resource_class ' ]);
61
+ foreach ($ resourceCollection as $ resource ) {
62
+ foreach ($ resource ->getOperations () as $ op ) {
63
+ if ($ op ->getUriTemplate () === $ operation ->getUriTemplate ()) {
64
+ $ allowedMethods [] = $ method = $ op ->getMethod ();
65
+ if ('POST ' === $ method && \is_array ($ outputFormats = $ op ->getOutputFormats ())) {
67
66
$ response ->headers ->set ('Accept-Post ' , implode (', ' , array_merge (...array_values ($ outputFormats ))));
68
67
}
69
68
}
0 commit comments