Skip to content

Replace the old exception to status config with the new Symfony's YAML extension for PHP constants #1251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ private function addExceptionToStatusSection(ArrayNodeDefinition $rootNode)
}

if (defined($httpStatusCodeConstant = sprintf('%s::%s', Response::class, $httpStatusCode))) {
@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);

$httpStatusCode = constant($httpStatusCodeConstant);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ public function testDefaultConfig()
], $config);
}

public function testExceptionToStatusConfig()
/**
* @group legacy
* @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").
*/
public function testLegacyExceptionToStatusConfig()
{
$config = $this->processor->processConfiguration($this->configuration, [
'api_platform' => [
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ api_platform:
enable_nelmio_api_doc: true
exception_to_status:
Symfony\Component\Serializer\Exception\ExceptionInterface: 400
ApiPlatform\Core\Exception\InvalidArgumentException: 'HTTP_BAD_REQUEST'
ApiPlatform\Core\Exception\InvalidArgumentException: !php/const:Symfony\Component\HttpFoundation\Response::HTTP_BAD_REQUEST
http_cache:
invalidation:
enabled: true
Expand Down