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\Identifier\Normalizer\ChainIdentifierDenormalizer; |
18
|
|
|
use ApiPlatform\Core\Util\RequestAttributesExtractor; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @internal |
22
|
|
|
*/ |
23
|
|
|
class OperationDataProvider |
24
|
|
|
{ |
25
|
|
|
use OperationDataProviderTrait; |
26
|
|
|
|
27
|
|
|
public function __construct(CollectionDataProviderInterface $collectionDataProvider, ItemDataProviderInterface $itemDataProvider, SubresourceDataProviderInterface $subresourceDataProvider, ChainIdentifierDenormalizer $identifierDenormalizer) |
28
|
|
|
{ |
29
|
|
|
$this->collectionDataProvider = $collectionDataProvider; |
30
|
|
|
$this->itemDataProvider = $itemDataProvider; |
31
|
|
|
$this->subresourceDataProvider = $subresourceDataProvider; |
32
|
|
|
$this->identifierDenormalizer = $identifierDenormalizer; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function getDataFromRouteParameters(string $iri = null, array $parameters, array $context = []) |
36
|
|
|
{ |
37
|
|
|
if (!isset($parameters['_api_resource_class'])) { |
38
|
|
|
throw new InvalidArgumentException(sprintf('No resource associated to "%s".', $iri)); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$attributes = RequestAttributesExtractor::extractAttributesFromParameters($parameters); |
42
|
|
|
$identifiers = $this->extractIdentifiers($parameters, $attributes); |
43
|
|
|
$context[ChainIdentifierDenormalizer::HAS_IDENTIFIER_DENORMALIZER] = true; |
44
|
|
|
|
45
|
|
|
if (isset($attributes['subresource_operation_name'])) { |
46
|
|
|
return $this->getSubresourceData($identifiers, $attributes, $context); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $this->getItemData($identifiers, $attributes, $context); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|