|
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
|
|
|
namespace ApiPlatform\Core\Http\Action; |
|
13
|
|
|
|
|
14
|
|
|
use ApiPlatform\Core\Api\ItemDataProviderInterface; |
|
15
|
|
|
use ApiPlatform\Core\Exception\RuntimeException; |
|
16
|
|
|
use ApiPlatform\Core\Http\ItemDataProvider; |
|
17
|
|
|
use ApiPlatform\Core\Http\RequestAttributesExtractorInterface; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
19
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Default API action retrieving a resource (used for GET and DELETE methods). |
|
23
|
|
|
* |
|
24
|
|
|
* @author Kévin Dunglas <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
final class GetItemAction |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var ItemDataProvider |
|
30
|
|
|
*/ |
|
31
|
|
|
private $itemDataProvider; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var RequestAttributesExtractorInterface |
|
35
|
|
|
*/ |
|
36
|
|
|
private $attributesExtractor; |
|
37
|
|
|
|
|
38
|
|
|
public function __construct(ItemDataProviderInterface $itemDataProvider, RequestAttributesExtractorInterface $attributesExtractor) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->itemDataProvider = new ItemDataProvider($itemDataProvider); |
|
41
|
|
|
$this->attributesExtractor = $attributesExtractor; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Retrieves an item. |
|
46
|
|
|
* |
|
47
|
|
|
* @param Request $request |
|
48
|
|
|
* @param string|int $id |
|
49
|
|
|
* |
|
50
|
|
|
* @throws NotFoundHttpException |
|
51
|
|
|
* @throws RuntimeException |
|
52
|
|
|
* |
|
53
|
|
|
* @return mixed |
|
54
|
|
|
*/ |
|
55
|
|
|
public function __invoke(Request $request, $id) |
|
56
|
|
|
{ |
|
57
|
|
|
$attributesBag = $this->attributesExtractor->extract($request); |
|
58
|
|
|
|
|
59
|
|
|
return $this->itemDataProvider->getItem( |
|
60
|
|
|
$this->itemDataProvider, |
|
|
|
|
|
|
61
|
|
|
$attributesBag->getResourceClass(), |
|
62
|
|
|
$attributesBag->getItemOperationName(), |
|
63
|
|
|
$id |
|
|
|
|
|
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: