1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the API Platform project. |
5
|
|
|
* |
6
|
|
|
* (c) Kévin Dunglas <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace ApiPlatform\Core\DataProvider; |
15
|
|
|
|
16
|
|
|
use ApiPlatform\Core\Exception\InvalidArgumentException; |
17
|
|
|
use ApiPlatform\Core\Exception\InvalidIdentifierException; |
|
|
|
|
18
|
|
|
use ApiPlatform\Core\Exception\PropertyNotFoundException; |
19
|
|
|
use ApiPlatform\Core\Exception\RuntimeException; |
20
|
|
|
use ApiPlatform\Core\Identifier\Normalizer\ChainIdentifierDenormalizer; |
|
|
|
|
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @internal |
24
|
|
|
*/ |
25
|
|
|
trait OperationDataProviderTrait |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var CollectionDataProviderInterface |
29
|
|
|
*/ |
30
|
|
|
private $collectionDataProvider; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var ItemDataProviderInterface |
34
|
|
|
*/ |
35
|
|
|
private $itemDataProvider; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var SubresourceDataProviderInterface |
39
|
|
|
*/ |
40
|
|
|
private $subresourceDataProvider; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var ChainIdentifierDenormalizer |
44
|
|
|
*/ |
45
|
|
|
private $identifierDenormalizer; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Retrieves data for a collection operation. |
49
|
|
|
* |
50
|
|
|
* @return iterable|null |
51
|
|
|
*/ |
52
|
|
|
private function getCollectionData(array $attributes, array $context) |
53
|
|
|
{ |
54
|
|
|
return $this->collectionDataProvider->getCollection($attributes['resource_class'], $attributes['collection_operation_name'], $context); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Gets data for an item operation. |
59
|
|
|
* |
60
|
|
|
* @throws NotFoundHttpException |
61
|
|
|
* |
62
|
|
|
* @return object|null |
63
|
|
|
*/ |
64
|
|
|
private function getItemData($identifiers, array $attributes, array $context) |
65
|
|
|
{ |
66
|
|
|
try { |
67
|
|
|
return $this->itemDataProvider->getItem($attributes['resource_class'], $identifiers, $attributes['item_operation_name'], $context); |
68
|
|
|
} catch (PropertyNotFoundException $e) { |
69
|
|
|
return null; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Gets data for a nested operation. |
75
|
|
|
* |
76
|
|
|
* @throws NotFoundHttpException |
77
|
|
|
* @throws RuntimeException |
78
|
|
|
* |
79
|
|
|
* @return object|null |
80
|
|
|
*/ |
81
|
|
|
private function getSubresourceData($identifiers, array $attributes, array $context) |
82
|
|
|
{ |
83
|
|
|
if (!$this->subresourceDataProvider) { |
84
|
|
|
throw new RuntimeException('Subresources not supported'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return $this->subresourceDataProvider->getSubresource($attributes['resource_class'], $identifiers, $attributes['subresource_context'] + $context, $attributes['subresource_operation_name']); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param array $parameters - usually comes from $request->attributes->all() |
92
|
|
|
* |
93
|
|
|
* @throws InvalidIdentifierException |
94
|
|
|
*/ |
95
|
|
|
private function extractIdentifiers(array $parameters, array $attributes) |
96
|
|
|
{ |
97
|
|
|
if (isset($attributes['item_operation_name'])) { |
98
|
|
|
if (!isset($parameters['id'])) { |
99
|
|
|
throw new InvalidArgumentException('Parameter "id" not found'); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return $parameters['id']; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$identifiers = []; |
106
|
|
|
|
107
|
|
|
foreach ($attributes['subresource_context']['identifiers'] as $key => list($id, $resourceClass, $hasIdentifier)) { |
108
|
|
|
if (false === $hasIdentifier) { |
109
|
|
|
continue; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
$identifiers[$id] = $parameters[$id]; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return $identifiers; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths