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

api-platform / core / 7142557150

08 Dec 2023 02:28PM UTC coverage: 36.003% (-1.4%) from 37.36%
7142557150

push

github

web-flow
fix(jsonld): remove link to ApiDocumentation when doc is disabled (#6029)

0 of 1 new or added line in 1 file covered. (0.0%)

2297 existing lines in 182 files now uncovered.

9992 of 27753 relevant lines covered (36.0%)

147.09 hits per line

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

11.54
/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
 * @deprecated
30
 *
31
 * @author Kévin Dunglas <dunglas@gmail.com>
32
 */
33
final class ValidationExceptionListener
34
{
35
    public function __construct(private readonly SerializerInterface $serializer, private readonly array $errorFormats, private readonly array $exceptionToStatus = [], private readonly ?ExceptionListener $exceptionListener = null)
36
    {
37
    }
2,496✔
38

39
    /**
40
     * Returns a list of violations normalized in the Hydra format.
41
     */
42
    public function onKernelException(ExceptionEvent $event): void
43
    {
44
        // API Platform 3.2 handles every exception through the exception listener so we just skip this one
45
        if ($this->exceptionListener) {
303✔
46
            return;
303✔
47
        }
48

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

UNCOV
51
        $exception = $event->getThrowable();
×
UNCOV
52
        if (!$exception instanceof ConstraintViolationListAwareExceptionInterface && !$exception instanceof FilterValidationException) {
×
UNCOV
53
            return;
×
54
        }
UNCOV
55
        $exceptionClass = $exception::class;
×
UNCOV
56
        $statusCode = Response::HTTP_UNPROCESSABLE_ENTITY;
×
57

UNCOV
58
        foreach ($this->exceptionToStatus as $class => $status) {
×
UNCOV
59
            if (is_a($exceptionClass, $class, true)) {
×
UNCOV
60
                $statusCode = $status;
×
61

UNCOV
62
                break;
×
63
            }
64
        }
65

UNCOV
66
        $format = ErrorFormatGuesser::guessErrorFormat($event->getRequest(), $this->errorFormats);
×
67

UNCOV
68
        $context = [];
×
UNCOV
69
        if ($exception instanceof ValidationException && ($errorTitle = $exception->getErrorTitle())) {
×
UNCOV
70
            $context['title'] = $errorTitle;
×
71
        }
72

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