-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjectProvider.php
36 lines (31 loc) · 1.05 KB
/
ObjectProvider.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
<?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\State;
use ApiPlatform\Exception\RuntimeException;
use ApiPlatform\Metadata\Operation;
/**
* An ItemProvider that just creates a new object.
*
* @author Antoine Bluchet <[email protected]>
*
* @experimental
*/
final class ObjectProvider implements ProviderInterface
{
public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?object
{
try {
return new ($operation->getClass());
} catch (\Throwable $e) {
throw new RuntimeException(sprintf('An error occurred while trying to create an instance of the "%s" resource. Consider writing your own "%s" implementation and setting it as `provider` on your operation instead.', $operation->getClass(), ProviderInterface::class), 0, $e);
}
}
}