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

api-platform / core / 6067528200

04 Sep 2023 12:12AM UTC coverage: 36.875% (-21.9%) from 58.794%
6067528200

Pull #5791

github

web-flow
Merge 64157e578 into d09cfc9d2
Pull Request #5791: fix: strip down any sql function name

3096 of 3096 new or added lines in 205 files covered. (100.0%)

9926 of 26918 relevant lines covered (36.87%)

6.5 hits per line

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

80.77
/src/Symfony/Controller/MainController.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\Controller;
15

16
use ApiPlatform\Api\UriVariablesConverterInterface;
17
use ApiPlatform\Exception\InvalidIdentifierException;
18
use ApiPlatform\Exception\InvalidUriVariableException;
19
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
20
use ApiPlatform\State\ProcessorInterface;
21
use ApiPlatform\State\ProviderInterface;
22
use ApiPlatform\State\UriVariablesResolverTrait;
23
use ApiPlatform\Util\OperationRequestInitiatorTrait;
24
use Psr\Log\LoggerInterface;
25
use Symfony\Component\HttpFoundation\Request;
26
use Symfony\Component\HttpFoundation\Response;
27
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
28

29
final class MainController
30
{
31
    use OperationRequestInitiatorTrait;
32
    use UriVariablesResolverTrait;
33

34
    public function __construct(
35
        ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory,
36
        private readonly ProviderInterface $provider,
37
        private readonly ProcessorInterface $processor,
38
        UriVariablesConverterInterface $uriVariablesConverter = null,
39
        private readonly ?LoggerInterface $logger = null
40
    ) {
41
        $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
28✔
42
        $this->uriVariablesConverter = $uriVariablesConverter;
28✔
43
    }
44

45
    public function __invoke(Request $request): Response
46
    {
47
        $operation = $this->initializeOperation($request);
28✔
48
        $uriVariables = [];
28✔
49
        try {
50
            $uriVariables = $this->getOperationUriVariables($operation, $request->attributes->all(), $operation->getClass());
28✔
51
        } catch (InvalidIdentifierException|InvalidUriVariableException $e) {
×
52
            throw new NotFoundHttpException('Invalid uri variables.', $e);
×
53
        }
54

55
        $context = [
28✔
56
            'request' => $request,
28✔
57
            'uri_variables' => $uriVariables,
28✔
58
            'resource_class' => $operation->getClass(),
28✔
59
        ];
28✔
60

61
        if (null === $operation->canValidate()) {
28✔
62
            $operation = $operation->withValidate(!$request->isMethodSafe() && !$request->isMethod('DELETE'));
28✔
63
        }
64

65
        $body = $this->provider->provide($operation, $uriVariables, $context);
28✔
66

67
        // The provider can change the Operation, extract it again from the Request attributes
68
        if ($request->attributes->get('_api_operation') !== $operation) {
28✔
69
            $operation = $this->initializeOperation($request);
28✔
70
            try {
71
                $uriVariables = $this->getOperationUriVariables($operation, $request->attributes->all(), $operation->getClass());
28✔
72
            } catch (InvalidIdentifierException|InvalidUriVariableException $e) {
×
73
                // if this occurs with our base operation we throw above so log instead of throw here
74
                if ($this->logger) {
×
75
                    $this->logger->error($e->getMessage(), ['operation' => $operation]);
×
76
                }
77
            }
78
        }
79

80
        $context['previous_data'] = $request->attributes->get('previous_data');
28✔
81
        $context['data'] = $request->attributes->get('data');
28✔
82

83
        if (null === $operation->canWrite()) {
28✔
84
            $operation = $operation->withWrite(!$request->isMethodSafe());
28✔
85
        }
86

87
        return $this->processor->process($body, $operation, $uriVariables, $context);
28✔
88
    }
89
}
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

© 2026 Coveralls, Inc