• 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

92.59
/src/Symfony/Validator/EventListener/ValidationExceptionListener.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\Validator\EventListener;
15

16
use ApiPlatform\Exception\FilterValidationException;
17
use ApiPlatform\Symfony\EventListener\ExceptionListener;
18
use ApiPlatform\Symfony\Validator\Exception\ConstraintViolationListAwareExceptionInterface;
19
use ApiPlatform\Util\ErrorFormatGuesser;
20
use ApiPlatform\Validator\Exception\ValidationException;
21
use Symfony\Component\HttpFoundation\Response;
22
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
23
use Symfony\Component\Serializer\SerializerInterface;
24

25
/**
26
 * Handles validation errors.
27
 * todo remove this class.
28
 *
29
 * @author Kévin Dunglas <dunglas@gmail.com>
30
 */
31
final class ValidationExceptionListener
32
{
33
    public function __construct(private readonly SerializerInterface $serializer, private readonly array $errorFormats, private readonly array $exceptionToStatus = [], private readonly ?ExceptionListener $exceptionListener = null)
34
    {
35
    }
87✔
36

37
    /**
38
     * Returns a list of violations normalized in the Hydra format.
39
     */
40
    public function onKernelException(ExceptionEvent $event): void
41
    {
42
        if ($this->exceptionListener) {
15✔
43
            $this->exceptionListener->onKernelException($event);
×
44

45
            return;
×
46
        }
47

48
        trigger_deprecation('api-platform', '3.2', sprintf('The class "%s" is deprecated and will be removed in 4.x.', __CLASS__));
15✔
49

50
        $exception = $event->getThrowable();
15✔
51
        if (!$exception instanceof ConstraintViolationListAwareExceptionInterface && !$exception instanceof FilterValidationException) {
15✔
52
            return;
3✔
53
        }
54
        $exceptionClass = $exception::class;
12✔
55
        $statusCode = Response::HTTP_UNPROCESSABLE_ENTITY;
12✔
56

57
        foreach ($this->exceptionToStatus as $class => $status) {
12✔
58
            if (is_a($exceptionClass, $class, true)) {
3✔
59
                $statusCode = $status;
3✔
60

61
                break;
3✔
62
            }
63
        }
64

65
        $format = ErrorFormatGuesser::guessErrorFormat($event->getRequest(), $this->errorFormats);
12✔
66

67
        $context = [];
12✔
68
        if ($exception instanceof ValidationException && ($errorTitle = $exception->getErrorTitle())) {
12✔
69
            $context['title'] = $errorTitle;
3✔
70
        }
71

72
        $event->setResponse(new Response(
12✔
73
            $this->serializer->serialize($exception instanceof ConstraintViolationListAwareExceptionInterface ? $exception->getConstraintViolationList() : $exception, $format['key'], $context),
12✔
74
            $statusCode,
12✔
75
            [
12✔
76
                'Content-Type' => sprintf('%s; charset=utf-8', $format['value'][0]),
12✔
77
                'X-Content-Type-Options' => 'nosniff',
12✔
78
                'X-Frame-Options' => 'deny',
12✔
79
            ]
12✔
80
        ));
12✔
81
    }
82
}
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