-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathElasticsearchProviderResourceMetadataCollectionFactory.php
78 lines (60 loc) · 2.79 KB
/
ElasticsearchProviderResourceMetadataCollectionFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace ApiPlatform\Elasticsearch\Metadata\Resource\Factory;
use ApiPlatform\Elasticsearch\State\CollectionProvider;
use ApiPlatform\Elasticsearch\State\ItemProvider;
use ApiPlatform\Elasticsearch\State\Options;
use ApiPlatform\Metadata\CollectionOperationInterface;
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
final class ElasticsearchProviderResourceMetadataCollectionFactory implements ResourceMetadataCollectionFactoryInterface
{
public function __construct(private readonly ResourceMetadataCollectionFactoryInterface $decorated)
{
}
/**
* {@inheritdoc}
*/
public function create(string $resourceClass): ResourceMetadataCollection
{
$resourceMetadataCollection = $this->decorated->create($resourceClass);
foreach ($resourceMetadataCollection as $i => $resourceMetadata) {
$operations = $resourceMetadata->getOperations();
if ($operations) {
foreach ($resourceMetadata->getOperations() as $operationName => $operation) {
if ($operation->getProvider()) {
continue;
}
if (!$operation->getStateOptions() instanceof Options) {
continue;
}
$operations->add($operationName, $operation->withProvider($operation instanceof CollectionOperationInterface ? CollectionProvider::class : ItemProvider::class));
}
$resourceMetadata = $resourceMetadata->withOperations($operations);
}
$graphQlOperations = $resourceMetadata->getGraphQlOperations();
if ($graphQlOperations) {
foreach ($graphQlOperations as $operationName => $graphQlOperation) {
if ($graphQlOperation->getProvider()) {
continue;
}
if (!$graphQlOperation->getStateOptions() instanceof Options) {
continue;
}
$graphQlOperations[$operationName] = $graphQlOperation->withProvider($graphQlOperation instanceof CollectionOperationInterface ? CollectionProvider::class : ItemProvider::class);
}
$resourceMetadata = $resourceMetadata->withGraphQlOperations($graphQlOperations);
}
$resourceMetadataCollection[$i] = $resourceMetadata;
}
return $resourceMetadataCollection;
}
}