Skip to content

Commit 56db34a

Browse files
committed
Use renamed HttpKernel event classes
To ensure forward compatibility with Symfony 5.0
1 parent 6f6e23c commit 56db34a

File tree

49 files changed

+222
-225
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+222
-225
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"psr/cache": "^1.0",
2020
"psr/container": "^1.0",
2121
"symfony/http-foundation": "^4.3.6 || ^5.0",
22-
"symfony/http-kernel": "^3.4 || ^4.0 || ^5.0",
22+
"symfony/http-kernel": "^4.3 || ^5.0",
2323
"symfony/property-access": "^3.4 || ^4.0 || ^5.0",
2424
"symfony/property-info": "^3.4 || ^4.0 || ^5.0",
2525
"symfony/serializer": "^4.3 || ^5.0",

phpstan.neon.dist

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ parameters:
2525
path: %currentWorkingDirectory%/src/Identifier/Normalizer/IntegerDenormalizer.php
2626

2727
# False positives
28-
- '#Class Symfony\\Component\\ErrorRenderer\\ErrorRenderer not found\.#'
2928
-
3029
message: '#Variable \$positionPm might not be defined\.#'
3130
path: %currentWorkingDirectory%/src/Util/ClassInfoTrait.php
@@ -107,3 +106,14 @@ parameters:
107106
- '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Filter\\(Abstract|Exists|Order)Filter::filterProperty\(\) invoked with 7 parameters, 5-6 required\.#'
108107
- '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Filter\\(AbstractFilter|FilterInterface)::apply\(\) invoked with 5 parameters, 3-4 required\.#'
109108
- '#Method ApiPlatform\\Core\\PathResolver\\OperationPathResolverInterface::resolveOperationPath\(\) invoked with 4 parameters, 3 required\.#'
109+
110+
# Expected, due to forward compatibility
111+
-
112+
message: '#Class Symfony\\Component\\ErrorRenderer\\ErrorRenderer not found\.#'
113+
path: %currentWorkingDirectory%/tests/Fixtures/app/AppKernel.php
114+
-
115+
message: '#Parameter \$exception of method ApiPlatform\\Core\\Action\\ExceptionAction::__invoke\(\) has invalid typehint type Symfony\\Component\\ErrorRenderer\\Exception\\FlattenException\.#'
116+
path: %currentWorkingDirectory%/src/Action/ExceptionAction.php
117+
-
118+
message: '#Call to method get(Class|Headers|StatusCode)\(\) on an unknown class Symfony\\Component\\ErrorRenderer\\Exception\\FlattenException\.#'
119+
path: %currentWorkingDirectory%/src/Action/ExceptionAction.php

src/Action/ExceptionAction.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,14 @@
1414
namespace ApiPlatform\Core\Action;
1515

1616
use ApiPlatform\Core\Util\ErrorFormatGuesser;
17-
use Symfony\Component\Debug\Exception\FlattenException;
17+
use Symfony\Component\Debug\Exception\FlattenException as LegacyFlattenException;
18+
use Symfony\Component\ErrorRenderer\Exception\FlattenException;
1819
use Symfony\Component\HttpFoundation\Request;
1920
use Symfony\Component\HttpFoundation\Response;
2021
use Symfony\Component\Serializer\SerializerInterface;
2122

2223
/**
23-
* Renders a normalized exception for a given {@see FlattenException}.
24-
*
25-
* Usage:
26-
*
27-
* $exceptionAction = new ExceptionAction(
28-
* new Serializer(),
29-
* [
30-
* 'jsonproblem' => ['application/problem+json'],
31-
* 'jsonld' => ['application/ld+json'],
32-
* ],
33-
* [
34-
* ExceptionInterface::class => Response::HTTP_BAD_REQUEST,
35-
* InvalidArgumentException::class => Response::HTTP_BAD_REQUEST,
36-
* ]
37-
* );
24+
* Renders a normalized exception for a given {@see FlattenException} or {@see LegacyFlattenException}.
3825
*
3926
* @author Baptiste Meyer <[email protected]>
4027
* @author Kévin Dunglas <[email protected]>
@@ -46,7 +33,7 @@ final class ExceptionAction
4633
private $exceptionToStatus;
4734

4835
/**
49-
* @param array $errorFormats A list of enabled formats, the first one will be the default
36+
* @param array $errorFormats A list of enabled error formats
5037
* @param array $exceptionToStatus A list of exceptions mapped to their HTTP status code
5138
*/
5239
public function __construct(SerializerInterface $serializer, array $errorFormats, array $exceptionToStatus = [])
@@ -59,7 +46,7 @@ public function __construct(SerializerInterface $serializer, array $errorFormats
5946
/**
6047
* Converts an exception to a JSON response.
6148
*
62-
* @param FlattenException $exception
49+
* @param FlattenException|LegacyFlattenException $exception
6350
*/
6451
public function __invoke($exception, Request $request): Response
6552
{

src/Bridge/Doctrine/EventListener/WriteListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use ApiPlatform\Core\EventListener\WriteListener as BaseWriteListener;
1717
use Doctrine\Common\Persistence\ManagerRegistry;
1818
use Doctrine\Common\Persistence\ObjectManager;
19-
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
19+
use Symfony\Component\HttpKernel\Event\ViewEvent;
2020

2121
/**
2222
* Bridges Doctrine and the API system.
@@ -39,7 +39,7 @@ public function __construct(ManagerRegistry $managerRegistry)
3939
/**
4040
* Persists, updates or delete data return by the controller if applicable.
4141
*/
42-
public function onKernelView(GetResponseForControllerResultEvent $event): void
42+
public function onKernelView(ViewEvent $event): void
4343
{
4444
$request = $event->getRequest();
4545
if ($request->isMethodSafe()) {

src/Bridge/FosUser/EventListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use ApiPlatform\Core\Util\RequestAttributesExtractor;
1717
use FOS\UserBundle\Model\UserInterface;
1818
use FOS\UserBundle\Model\UserManagerInterface;
19-
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
19+
use Symfony\Component\HttpKernel\Event\ViewEvent;
2020

2121
/**
2222
* Bridges between FOSUserBundle and API Platform Core.
@@ -36,7 +36,7 @@ public function __construct(UserManagerInterface $userManager)
3636
/**
3737
* Persists, updates or delete data return by the controller if applicable.
3838
*/
39-
public function onKernelView(GetResponseForControllerResultEvent $event): void
39+
public function onKernelView(ViewEvent $event): void
4040
{
4141
$request = $event->getRequest();
4242
if (!RequestAttributesExtractor::extractAttributes($request)) {

src/Bridge/Symfony/Bundle/EventListener/SwaggerUiListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313

1414
namespace ApiPlatform\Core\Bridge\Symfony\Bundle\EventListener;
1515

16-
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
16+
use Symfony\Component\HttpKernel\Event\RequestEvent;
1717

1818
final class SwaggerUiListener
1919
{
2020
/**
2121
* Sets SwaggerUiAction as controller if the requested format is HTML.
2222
*/
23-
public function onKernelRequest(GetResponseEvent $event): void
23+
public function onKernelRequest(RequestEvent $event): void
2424
{
2525
$request = $event->getRequest();
2626
if (

src/Bridge/Symfony/Validator/EventListener/ValidateListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use ApiPlatform\Core\Util\RequestAttributesExtractor;
1919
use ApiPlatform\Core\Validator\EventListener\ValidateListener as MainValidateListener;
2020
use Psr\Container\ContainerInterface;
21-
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
21+
use Symfony\Component\HttpKernel\Event\ViewEvent;
2222
use Symfony\Component\Validator\Validator\ValidatorInterface;
2323

2424
/**
@@ -48,7 +48,7 @@ public function __construct(ValidatorInterface $validator, ResourceMetadataFacto
4848
*
4949
* @throws ValidationException
5050
*/
51-
public function onKernelView(GetResponseForControllerResultEvent $event): void
51+
public function onKernelView(ViewEvent $event): void
5252
{
5353
$request = $event->getRequest();
5454
if (

src/Bridge/Symfony/Validator/EventListener/ValidationExceptionListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use ApiPlatform\Core\Bridge\Symfony\Validator\Exception\ValidationException;
1717
use ApiPlatform\Core\Util\ErrorFormatGuesser;
1818
use Symfony\Component\HttpFoundation\Response;
19-
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
19+
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
2020
use Symfony\Component\Serializer\SerializerInterface;
2121

2222
/**
@@ -38,7 +38,7 @@ public function __construct(SerializerInterface $serializer, array $errorFormats
3838
/**
3939
* Returns a list of violations normalized in the Hydra format.
4040
*/
41-
public function onKernelException(GetResponseForExceptionEvent $event): void
41+
public function onKernelException(ExceptionEvent $event): void
4242
{
4343
$exception = $event->getException();
4444
if (!$exception instanceof ValidationException) {

src/EventListener/AddFormatListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use ApiPlatform\Core\Util\RequestAttributesExtractor;
2020
use Negotiation\Negotiator;
2121
use Symfony\Component\HttpFoundation\Request;
22-
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
22+
use Symfony\Component\HttpKernel\Event\RequestEvent;
2323
use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException;
2424
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
2525

@@ -62,7 +62,7 @@ public function __construct(Negotiator $negotiator, $resourceMetadataFactory, ar
6262
* @throws NotFoundHttpException
6363
* @throws NotAcceptableHttpException
6464
*/
65-
public function onKernelRequest(GetResponseEvent $event): void
65+
public function onKernelRequest(RequestEvent $event): void
6666
{
6767
$request = $event->getRequest();
6868
if (

src/EventListener/DeserializeListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use ApiPlatform\Core\Serializer\SerializerContextBuilderInterface;
2121
use ApiPlatform\Core\Util\RequestAttributesExtractor;
2222
use Symfony\Component\HttpFoundation\Request;
23-
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
23+
use Symfony\Component\HttpKernel\Event\RequestEvent;
2424
use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException;
2525
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
2626
use Symfony\Component\Serializer\SerializerInterface;
@@ -66,7 +66,7 @@ public function __construct(SerializerInterface $serializer, SerializerContextBu
6666
*
6767
* @throws UnsupportedMediaTypeHttpException
6868
*/
69-
public function onKernelRequest(GetResponseEvent $event): void
69+
public function onKernelRequest(RequestEvent $event): void
7070
{
7171
$request = $event->getRequest();
7272
$method = $request->getMethod();

src/EventListener/ExceptionListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
use ApiPlatform\Core\Util\RequestAttributesExtractor;
1717
use Psr\Log\LoggerInterface;
18-
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
18+
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
1919
use Symfony\Component\HttpKernel\EventListener\ExceptionListener as BaseExceptionListener;
2020

2121
/**
@@ -33,7 +33,7 @@ public function __construct($controller, LoggerInterface $logger = null, $debug
3333
$this->exceptionListener = new BaseExceptionListener($controller, $logger, $debug);
3434
}
3535

36-
public function onKernelException(GetResponseForExceptionEvent $event): void
36+
public function onKernelException(ExceptionEvent $event): void
3737
{
3838
$request = $event->getRequest();
3939
// Normalize exceptions only for routes managed by API Platform

src/EventListener/ReadListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
use ApiPlatform\Core\Util\CloneTrait;
2727
use ApiPlatform\Core\Util\RequestAttributesExtractor;
2828
use ApiPlatform\Core\Util\RequestParser;
29-
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
29+
use Symfony\Component\HttpKernel\Event\RequestEvent;
3030
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
3131

3232
/**
@@ -59,7 +59,7 @@ public function __construct(CollectionDataProviderInterface $collectionDataProvi
5959
*
6060
* @throws NotFoundHttpException
6161
*/
62-
public function onKernelRequest(GetResponseEvent $event): void
62+
public function onKernelRequest(RequestEvent $event): void
6363
{
6464
$request = $event->getRequest();
6565
if (

src/EventListener/RespondListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;
1818
use ApiPlatform\Core\Util\RequestAttributesExtractor;
1919
use Symfony\Component\HttpFoundation\Response;
20-
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
20+
use Symfony\Component\HttpKernel\Event\ViewEvent;
2121

2222
/**
2323
* Builds the response object.
@@ -41,7 +41,7 @@ public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFa
4141
/**
4242
* Creates a Response to send to the client according to the requested format.
4343
*/
44-
public function onKernelView(GetResponseForControllerResultEvent $event): void
44+
public function onKernelView(ViewEvent $event): void
4545
{
4646
$controllerResult = $event->getControllerResult();
4747
$request = $event->getRequest();

src/EventListener/SerializeListener.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use Fig\Link\Link;
2424
use Symfony\Component\HttpFoundation\Request;
2525
use Symfony\Component\HttpFoundation\Response;
26-
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
26+
use Symfony\Component\HttpKernel\Event\ViewEvent;
2727
use Symfony\Component\Serializer\Encoder\EncoderInterface;
2828
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
2929
use Symfony\Component\Serializer\SerializerInterface;
@@ -52,7 +52,7 @@ public function __construct(SerializerInterface $serializer, SerializerContextBu
5252
/**
5353
* Serializes the data to the requested format.
5454
*/
55-
public function onKernelView(GetResponseForControllerResultEvent $event): void
55+
public function onKernelView(ViewEvent $event): void
5656
{
5757
$controllerResult = $event->getControllerResult();
5858
$request = $event->getRequest();
@@ -113,7 +113,7 @@ public function onKernelView(GetResponseForControllerResultEvent $event): void
113113
*
114114
* @throws RuntimeException
115115
*/
116-
private function serializeRawData(GetResponseForControllerResultEvent $event, Request $request, $controllerResult): void
116+
private function serializeRawData(ViewEvent $event, Request $request, $controllerResult): void
117117
{
118118
if (\is_object($controllerResult)) {
119119
$event->setControllerResult($this->serializer->serialize($controllerResult, $request->getRequestFormat(), $request->attributes->get('_api_normalization_context', [])));

src/EventListener/WriteListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use ApiPlatform\Core\Util\RequestAttributesExtractor;
2222
use ApiPlatform\Core\Util\ResourceClassInfoTrait;
2323
use Symfony\Component\HttpFoundation\Response;
24-
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
24+
use Symfony\Component\HttpKernel\Event\ViewEvent;
2525

2626
/**
2727
* Bridges persistence and the API system.
@@ -50,7 +50,7 @@ public function __construct(DataPersisterInterface $dataPersister, IriConverterI
5050
/**
5151
* Persists, updates or delete data return by the controller if applicable.
5252
*/
53-
public function onKernelView(GetResponseForControllerResultEvent $event): void
53+
public function onKernelView(ViewEvent $event): void
5454
{
5555
$controllerResult = $event->getControllerResult();
5656
$request = $event->getRequest();

src/Filter/QueryParameterValidateListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use ApiPlatform\Core\Util\RequestAttributesExtractor;
2020
use Psr\Container\ContainerInterface;
2121
use Symfony\Component\HttpFoundation\Request;
22-
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
22+
use Symfony\Component\HttpKernel\Event\RequestEvent;
2323

2424
/**
2525
* Validates query parameters depending on filter description.
@@ -38,7 +38,7 @@ public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFa
3838
$this->setFilterLocator($filterLocator);
3939
}
4040

41-
public function onKernelRequest(GetResponseEvent $event): void
41+
public function onKernelRequest(RequestEvent $event): void
4242
{
4343
$request = $event->getRequest();
4444
if (

src/HttpCache/EventListener/AddHeadersListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
1717
use ApiPlatform\Core\Util\RequestAttributesExtractor;
18-
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
18+
use Symfony\Component\HttpKernel\Event\ResponseEvent;
1919

2020
/**
2121
* Configures cache HTTP headers for the current response.
@@ -43,7 +43,7 @@ public function __construct(bool $etag = false, int $maxAge = null, int $sharedM
4343
$this->resourceMetadataFactory = $resourceMetadataFactory;
4444
}
4545

46-
public function onKernelResponse(FilterResponseEvent $event): void
46+
public function onKernelResponse(ResponseEvent $event): void
4747
{
4848
$request = $event->getRequest();
4949
if (!$request->isMethodCacheable() || !RequestAttributesExtractor::extractAttributes($request)) {

src/HttpCache/EventListener/AddTagsListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
use ApiPlatform\Core\Api\IriConverterInterface;
1717
use ApiPlatform\Core\Util\RequestAttributesExtractor;
18-
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
18+
use Symfony\Component\HttpKernel\Event\ResponseEvent;
1919

2020
/**
2121
* Sets the list of resources' IRIs included in this response in the "Cache-Tags" HTTP header.
@@ -40,7 +40,7 @@ public function __construct(IriConverterInterface $iriConverter)
4040
/**
4141
* Adds the "Cache-Tags" header.
4242
*/
43-
public function onKernelResponse(FilterResponseEvent $event): void
43+
public function onKernelResponse(ResponseEvent $event): void
4444
{
4545
$request = $event->getRequest();
4646
$response = $event->getResponse();

src/Hydra/EventListener/AddLinkHeaderListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use ApiPlatform\Core\JsonLd\ContextBuilder;
1818
use Fig\Link\GenericLinkProvider;
1919
use Fig\Link\Link;
20-
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
20+
use Symfony\Component\HttpKernel\Event\ResponseEvent;
2121

2222
/**
2323
* Adds the HTTP Link header pointing to the Hydra documentation.
@@ -36,7 +36,7 @@ public function __construct(UrlGeneratorInterface $urlGenerator)
3636
/**
3737
* Sends the Hydra header on each response.
3838
*/
39-
public function onKernelResponse(FilterResponseEvent $event): void
39+
public function onKernelResponse(ResponseEvent $event): void
4040
{
4141
$apiDocUrl = $this->urlGenerator->generate('api_doc', ['_format' => 'jsonld'], UrlGeneratorInterface::ABS_URL);
4242
$link = new Link(ContextBuilder::HYDRA_NS.'apiDocumentation', $apiDocUrl);

src/JsonApi/EventListener/TransformFieldsetsParametersListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace ApiPlatform\Core\JsonApi\EventListener;
1515

1616
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
17-
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
17+
use Symfony\Component\HttpKernel\Event\RequestEvent;
1818

1919
/**
2020
* @see http://jsonapi.org/format/#fetching-sparse-fieldsets
@@ -31,7 +31,7 @@ public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFa
3131
$this->resourceMetadataFactory = $resourceMetadataFactory;
3232
}
3333

34-
public function onKernelRequest(GetResponseEvent $event): void
34+
public function onKernelRequest(RequestEvent $event): void
3535
{
3636
$request = $event->getRequest();
3737

0 commit comments

Comments
 (0)