Skip to content

Commit 432c580

Browse files
authored
Merge pull request #3259 from chalasr/error-handler
Fix symfony/error-handler compatibility
2 parents 5c67772 + d5a222f commit 432c580

File tree

8 files changed

+24
-21
lines changed

8 files changed

+24
-21
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"symfony/config": "^3.4 || ^4.0 || ^5.0",
6767
"symfony/console": "^3.4 || ^4.0 || ^5.0",
6868
"symfony/css-selector": "^3.4 || ^4.0 || ^5.0",
69-
"symfony/debug": "^3.4 || ^4.0 || ^5.0",
69+
"symfony/debug": "^3.4 || ^4.0",
7070
"symfony/dependency-injection": "^3.4 || ^4.0 || ^5.0",
7171
"symfony/doctrine-bridge": "^3.4 || ^4.0 || ^5.0",
7272
"symfony/dom-crawler": "^3.4 || ^4.0 || ^5.0",

phpstan.neon.dist

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,10 @@ parameters:
109109

110110
# Expected, due to forward compatibility
111111
-
112-
message: '#Class Symfony\\Component\\ErrorRenderer\\ErrorRenderer not found\.#'
112+
message: '#Class Symfony\\Component\\ErrorHandler\\ErrorRenderer\\ErrorRendererInterface not found\.#'
113113
path: %currentWorkingDirectory%/tests/Fixtures/app/AppKernel.php
114114
-
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\.#'
115+
message: '#Parameter \$exception of method ApiPlatform\\Core\\Action\\ExceptionAction::__invoke\(\) has invalid typehint type Symfony\\Component\\ErrorHandler\\Exception\\FlattenException\.#'
119116
path: %currentWorkingDirectory%/src/Action/ExceptionAction.php
117+
- '#Call to method get(Class|Headers|StatusCode)\(\) on an unknown class Symfony\\Component\\ErrorHandler\\Exception\\FlattenException\.#'
118+
- '#Class Symfony\\Component\\ErrorHandler\\Exception\\FlattenException not found\.#'

src/Action/ExceptionAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
use ApiPlatform\Core\Util\ErrorFormatGuesser;
1717
use Symfony\Component\Debug\Exception\FlattenException as LegacyFlattenException;
18-
use Symfony\Component\ErrorRenderer\Exception\FlattenException;
18+
use Symfony\Component\ErrorHandler\Exception\FlattenException;
1919
use Symfony\Component\HttpFoundation\Request;
2020
use Symfony\Component\HttpFoundation\Response;
2121
use Symfony\Component\Serializer\SerializerInterface;

src/Hydra/Serializer/ErrorNormalizer.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515

1616
use ApiPlatform\Core\Api\UrlGeneratorInterface;
1717
use ApiPlatform\Core\Problem\Serializer\ErrorNormalizerTrait;
18-
use Symfony\Component\Debug\Exception\FlattenException;
18+
use Symfony\Component\Debug\Exception\FlattenException as LegacyFlattenException;
19+
use Symfony\Component\ErrorHandler\Exception\FlattenException;
1920
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
2021
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
2122

2223
/**
23-
* Converts {@see \Exception} or {@see \Symfony\Component\Debug\Exception\FlattenException} to a Hydra error representation.
24+
* Converts {@see \Exception} or {@see FlattenException} or {@see LegacyFlattenException} to a Hydra error representation.
2425
*
2526
* @author Kévin Dunglas <[email protected]>
2627
* @author Samuel ROZE <[email protected]>
@@ -67,7 +68,7 @@ public function normalize($object, $format = null, array $context = [])
6768
*/
6869
public function supportsNormalization($data, $format = null)
6970
{
70-
return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException);
71+
return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException || $data instanceof LegacyFlattenException);
7172
}
7273

7374
/**

src/JsonApi/Serializer/ErrorNormalizer.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
namespace ApiPlatform\Core\JsonApi\Serializer;
1515

1616
use ApiPlatform\Core\Problem\Serializer\ErrorNormalizerTrait;
17-
use Symfony\Component\Debug\Exception\FlattenException;
17+
use Symfony\Component\Debug\Exception\FlattenException as LegacyFlattenException;
18+
use Symfony\Component\ErrorHandler\Exception\FlattenException;
1819
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
1920
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
2021

2122
/**
22-
* Converts {@see \Exception} or {@see \Symfony\Component\Debug\Exception\FlattenException} to a JSON API error representation.
23+
* Converts {@see \Exception} or {@see FlattenException} or {@see LegacyFlattenException} to a JSON API error representation.
2324
*
2425
* @author Héctor Hurtarte <[email protected]>
2526
*/
@@ -60,7 +61,7 @@ public function normalize($object, $format = null, array $context = [])
6061
*/
6162
public function supportsNormalization($data, $format = null)
6263
{
63-
return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException);
64+
return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException || $data instanceof LegacyFlattenException);
6465
}
6566

6667
/**

src/Problem/Serializer/ErrorNormalizer.php

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

1414
namespace ApiPlatform\Core\Problem\Serializer;
1515

16-
use Symfony\Component\Debug\Exception\FlattenException;
16+
use Symfony\Component\Debug\Exception\FlattenException as LegacyFlattenException;
17+
use Symfony\Component\ErrorHandler\Exception\FlattenException;
1718
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
1819
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
1920

@@ -67,7 +68,7 @@ public function normalize($object, $format = null, array $context = [])
6768
*/
6869
public function supportsNormalization($data, $format = null)
6970
{
70-
return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException);
71+
return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException || $data instanceof LegacyFlattenException);
7172
}
7273

7374
/**

src/Problem/Serializer/ErrorNormalizerTrait.php

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

1414
namespace ApiPlatform\Core\Problem\Serializer;
1515

16-
use Symfony\Component\Debug\Exception\FlattenException;
16+
use Symfony\Component\Debug\Exception\FlattenException as LegacyFlattenException;
17+
use Symfony\Component\ErrorHandler\Exception\FlattenException;
1718
use Symfony\Component\HttpFoundation\Response;
1819

1920
trait ErrorNormalizerTrait
@@ -26,7 +27,7 @@ private function getErrorMessage($object, array $context, bool $debug = false):
2627
return $message;
2728
}
2829

29-
if ($object instanceof FlattenException) {
30+
if ($object instanceof FlattenException || $object instanceof LegacyFlattenException) {
3031
$statusCode = $context['statusCode'] ?? $object->getStatusCode();
3132
if ($statusCode >= 500 && $statusCode < 600) {
3233
$message = Response::$statusTexts[$statusCode];

tests/Fixtures/app/AppKernel.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
use Symfony\Bundle\WebProfilerBundle\WebProfilerBundle;
2828
use Symfony\Component\Config\Loader\LoaderInterface;
2929
use Symfony\Component\DependencyInjection\ContainerBuilder;
30-
use Symfony\Component\ErrorRenderer\ErrorRenderer;
30+
use Symfony\Component\ErrorHandler\ErrorRenderer\ErrorRendererInterface;
3131
use Symfony\Component\HttpKernel\Kernel;
3232
use Symfony\Component\Routing\RouteCollectionBuilder;
33-
use Symfony\Component\Security\Core\Encoder\SodiumPasswordEncoder;
33+
use Symfony\Component\Security\Core\Encoder\NativePasswordEncoder;
3434
use Symfony\Component\Security\Core\User\UserInterface;
3535

3636
/**
@@ -98,7 +98,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
9898

9999
$loader->load(__DIR__."/config/config_{$this->getEnvironment()}.yml");
100100

101-
$alg = class_exists(SodiumPasswordEncoder::class) && SodiumPasswordEncoder::isSupported() ? 'auto' : 'bcrypt';
101+
$alg = class_exists(NativePasswordEncoder::class) ? 'auto' : 'bcrypt';
102102
$securityConfig = [
103103
'encoders' => [
104104
User::class => $alg,
@@ -155,7 +155,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
155155
}
156156

157157
$twigConfig = ['strict_variables' => '%kernel.debug%'];
158-
if (class_exists(ErrorRenderer::class)) {
158+
if (interface_exists(ErrorRendererInterface::class)) {
159159
$twigConfig['exception_controller'] = null;
160160
}
161161
$c->prependExtensionConfig('twig', $twigConfig);

0 commit comments

Comments
 (0)