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

api-platform / core / 10508505187

22 Aug 2024 12:55PM UTC coverage: 7.704%. Remained the same
10508505187

push

github

soyuka
Merge 3.4

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

8840 existing lines in 284 files now uncovered.

12477 of 161949 relevant lines covered (7.7%)

22.99 hits per line

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

91.67
/src/Symfony/EventListener/ValidateListener.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\EventListener;
15

16
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
17
use ApiPlatform\State\ProviderInterface;
18
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
19
use ApiPlatform\Validator\Exception\ValidationException;
20
use Symfony\Component\HttpKernel\Event\ViewEvent;
21

22
/**
23
 * Validates data.
24
 *
25
 * @author Kévin Dunglas <dunglas@gmail.com>
26
 */
27
final class ValidateListener
28
{
29
    use OperationRequestInitiatorTrait;
30

31
    /**
32
     * @param ProviderInterface<object> $provider
33
     */
34
    public function __construct(private readonly ProviderInterface $provider, ?ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null)
35
    {
UNCOV
36
        $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
91✔
37
    }
38

39
    /**
40
     * Validates data returned by the controller if applicable.
41
     *
42
     * @throws ValidationException
43
     */
44
    public function onKernelView(ViewEvent $event): void
45
    {
UNCOV
46
        $request = $event->getRequest();
91✔
UNCOV
47
        $operation = $this->initializeOperation($request);
91✔
48

UNCOV
49
        if (!$operation) {
91✔
50
            return;
×
51
        }
52

UNCOV
53
        if (null === $operation->canValidate()) {
91✔
UNCOV
54
            $operation = $operation->withValidate(!$request->isMethodSafe() && !$request->isMethod('DELETE'));
91✔
55
        }
56

UNCOV
57
        $this->provider->provide($operation, $request->attributes->get('_api_uri_variables') ?? [], [
91✔
UNCOV
58
            'request' => $request,
91✔
UNCOV
59
            'uri_variables' => $request->attributes->get('_api_uri_variables') ?? [],
91✔
UNCOV
60
            'resource_class' => $operation->getClass(),
91✔
UNCOV
61
        ]);
91✔
62
    }
63
}
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