• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
You are now the owner of this repo.

api-platform / core / 3904303394

pending completion
3904303394

Pull #5332

github

GitHub
Merge 2e0a3ceae into 965332bc8
Pull Request #5332: Revert "chore(deprecation): Only use ValueResolverInterface if it exists"

2 of 2 new or added lines in 1 file covered. (100.0%)

7939 of 12085 relevant lines covered (65.69%)

81.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Symfony/Bundle/ArgumentResolver/PayloadArgumentResolver.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
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\Symfony\Bundle\ArgumentResolver;
15

16
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
17
use ApiPlatform\Serializer\SerializerContextBuilderInterface;
18
use ApiPlatform\Util\OperationRequestInitiatorTrait;
19
use ApiPlatform\Util\RequestAttributesExtractor;
20
use Symfony\Component\HttpFoundation\Request;
21
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
22
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
23

24
final class PayloadArgumentResolver implements ValueResolverInterface
25
{
26
    use OperationRequestInitiatorTrait;
27

28
    public function __construct(
29
        ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory,
30
        private readonly SerializerContextBuilderInterface $serializationContextBuilder
31
    ) {
32
        $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
×
33
    }
34

35
    public function supports(Request $request, ArgumentMetadata $argument): bool
36
    {
37
        if ($argument->isVariadic()) {
×
38
            return false;
×
39
        }
40

41
        $class = $argument->getType();
×
42

43
        if (null === $class) {
×
44
            return false;
×
45
        }
46

47
        if (null === $request->attributes->get('data')) {
×
48
            return false;
×
49
        }
50

51
        $inputClass = $this->getExpectedInputClass($request);
×
52

53
        if (null === $inputClass) {
×
54
            return false;
×
55
        }
56

57
        return $inputClass === $class || is_subclass_of($inputClass, $class);
×
58
    }
59

60
    public function resolve(Request $request, ArgumentMetadata $argument): \Generator
61
    {
62
        if (!$this->supports($request, $argument)) {
×
63
            yield [];
×
64
        }
65

66
        yield $request->attributes->get('data');
×
67
    }
68

69
    private function getExpectedInputClass(Request $request): ?string
70
    {
71
        $operation = $this->initializeOperation($request);
×
72
        if (Request::METHOD_DELETE === $request->getMethod() || $request->isMethodSafe() || !($operation?->canDeserialize() ?? true)) {
×
73
            return null;
×
74
        }
75

76
        $context = $this->serializationContextBuilder->createFromRequest($request, false, RequestAttributesExtractor::extractAttributes($request));
×
77

78
        return $context['input']['class'] ?? $context['resource_class'] ?? null;
×
79
    }
80
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc