Skip to content

Commit d2ee8fa

Browse files
authored
fix(symfony): add default item provider (#5039)
1 parent 36a8eee commit d2ee8fa

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

CreateProvider.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
5858
}
5959

6060
$relation = $this->decorated->provide(new Get(uriVariables: $relationUriVariables, class: $relationClass), $uriVariables);
61-
$resource = new ($operation->getClass());
61+
$refl = new \ReflectionClass($operation->getClass());
62+
$resource = $refl->newInstanceWithoutConstructor();
6263
$this->propertyAccessor->setValue($resource, $key, $relation);
6364

6465
return $resource;

ObjectProvider.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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\State;
15+
16+
use ApiPlatform\Metadata\Operation;
17+
18+
/**
19+
* An ItemProvider that just create a new object.
20+
*
21+
* @author Antoine Bluchet <[email protected]>
22+
*
23+
* @experimental
24+
*/
25+
final class ObjectProvider implements ProviderInterface
26+
{
27+
public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?object
28+
{
29+
$refl = new \ReflectionClass($operation->getClass());
30+
31+
return $refl->newInstanceWithoutConstructor();
32+
}
33+
}

0 commit comments

Comments
 (0)