• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 18223414080

03 Oct 2025 01:18PM UTC coverage: 0.0% (-22.0%) from 21.956%
18223414080

Pull #7397

github

web-flow
Merge 69d085182 into 0b8237918
Pull Request #7397: fix(jsonschema/jsonld): make `@id` and `@type` properties required only in the JSON-LD schema for output

0 of 18 new or added lines in 2 files covered. (0.0%)

12304 existing lines in 405 files now uncovered.

0 of 53965 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/src/State/CreateProvider.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\State;
15

16
use ApiPlatform\Metadata\Exception\RuntimeException;
17
use ApiPlatform\Metadata\HttpOperation;
18
use ApiPlatform\Metadata\Operation;
19
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
20
use ApiPlatform\State\Exception\ProviderNotFoundException;
21
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
22
use Symfony\Component\PropertyAccess\PropertyAccess;
23
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
24

25
/**
26
 * An ItemProvider for POST operations on generated subresources.
27
 *
28
 * @see ApiPlatform\Tests\Fixtures\TestBundle\Entity\SubresourceEmployee
29
 *
30
 * @author Antoine Bluchet <soyuka@gmail.com>
31
 */
32
final class CreateProvider implements ProviderInterface
33
{
34
    public function __construct(
35
        private ProviderInterface $decorated,
36
        private ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory,
37
        private ?PropertyAccessorInterface $propertyAccessor = null,
38
    ) {
UNCOV
39
        $this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
×
40
    }
41

42
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?object
43
    {
UNCOV
44
        if (!$uriVariables || !$operation instanceof HttpOperation || (null !== $operation->getController() && 'api_platform.symfony.main_controller' !== $operation->getController())) {
×
UNCOV
45
            return $this->decorated->provide($operation, $uriVariables, $context);
×
46
        }
47

UNCOV
48
        $operationUriVariables = $operation->getUriVariables();
×
UNCOV
49
        $relationClass = current($operationUriVariables)->getFromClass();
×
UNCOV
50
        $key = key($operationUriVariables);
×
51

UNCOV
52
        $parentOperation = $this->resourceMetadataCollectionFactory
×
UNCOV
53
            ->create($relationClass)
×
UNCOV
54
            ->getOperation($operation->getExtraProperties()['parent_uri_template'] ?? null);
×
55
        try {
UNCOV
56
            $relation = $this->decorated->provide($parentOperation, $uriVariables, $context);
×
UNCOV
57
        } catch (ProviderNotFoundException) {
×
UNCOV
58
            $relation = null;
×
59
        }
UNCOV
60
        if (!$relation) {
×
UNCOV
61
            throw new NotFoundHttpException('Not Found');
×
62
        }
63

64
        try {
UNCOV
65
            $resource = new ($operation->getClass());
×
UNCOV
66
        } catch (\Throwable $e) {
×
UNCOV
67
            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);
×
68
        }
69

UNCOV
70
        $property = $operationUriVariables[$key]->getToProperty() ?? $key;
×
UNCOV
71
        $this->propertyAccessor->setValue($resource, $property, $relation);
×
72

UNCOV
73
        return $resource;
×
74
    }
75
}
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