Skip to content

Commit 9c4a116

Browse files
authored
Merge pull request #1251 from meyerbaptiste/use_symfony_php_constants_yaml_extension
Replace the old exception to status config with the new Symfony's YAML extension for PHP constants
2 parents 78b2928 + 39172a9 commit 9c4a116

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ private function addExceptionToStatusSection(ArrayNodeDefinition $rootNode)
186186
}
187187

188188
if (defined($httpStatusCodeConstant = sprintf('%s::%s', Response::class, $httpStatusCode))) {
189+
@trigger_error(sprintf('Using a string "%s" as a constant of the "%s" class is deprecated since API Platform 2.1 and will not be possible anymore in API Platform 3. Use the Symfony\'s custom YAML extension for PHP constants instead (i.e. "!php/const:%s").', $httpStatusCode, Response::class, $httpStatusCodeConstant), E_USER_DEPRECATED);
190+
189191
$httpStatusCode = constant($httpStatusCodeConstant);
190192
}
191193
}

tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ public function testDefaultConfig()
120120
], $config);
121121
}
122122

123-
public function testExceptionToStatusConfig()
123+
/**
124+
* @group legacy
125+
* @expectedDeprecation Using a string "HTTP_INTERNAL_SERVER_ERROR" as a constant of the "Symfony\Component\HttpFoundation\Response" class is deprecated since API Platform 2.1 and will not be possible anymore in API Platform 3. Use the Symfony's custom YAML extension for PHP constants instead (i.e. "!php/const:Symfony\Component\HttpFoundation\Response::HTTP_BAD_REQUEST").
126+
*/
127+
public function testLegacyExceptionToStatusConfig()
124128
{
125129
$config = $this->processor->processConfiguration($this->configuration, [
126130
'api_platform' => [

tests/Fixtures/app/config/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ api_platform:
4848
enable_nelmio_api_doc: true
4949
exception_to_status:
5050
Symfony\Component\Serializer\Exception\ExceptionInterface: 400
51-
ApiPlatform\Core\Exception\InvalidArgumentException: 'HTTP_BAD_REQUEST'
51+
ApiPlatform\Core\Exception\InvalidArgumentException: !php/const:Symfony\Component\HttpFoundation\Response::HTTP_BAD_REQUEST
5252
http_cache:
5353
invalidation:
5454
enabled: true

0 commit comments

Comments
 (0)