Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpKernel] Create Attributes #[MapRequestPayload] and #[MapQueryString] to map Request input to typed objects #49138

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
merged 1 commit into from
Apr 14, 2023
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
[HttpKernel] Create Attributes #[MapRequestPayload] and `#[MapQuery…
…String]` to map Request input to typed objects
  • Loading branch information
Koc authored and nicolas-grekas committed Apr 14, 2023
commit d987093a538c70fc4a2d01b046913a2820341699
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class UnusedTagsPass implements CompilerPassInterface
'container.stack',
'controller.argument_value_resolver',
'controller.service_arguments',
'controller.targeted_value_resolver',
'data_collector',
'event_dispatcher.dispatcher',
'form.type',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\Normalizer\ProblemNormalizer;
use Symfony\Component\Serializer\Normalizer\UnwrappingDenormalizer;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\SerializerAwareInterface;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\String\LazyString;
Expand Down Expand Up @@ -357,11 +358,19 @@ public function load(array $configs, ContainerBuilder $container)
$container->getDefinition('exception_listener')->replaceArgument(3, $config['exceptions']);

if ($this->readConfigEnabled('serializer', $container, $config['serializer'])) {
if (!class_exists(\Symfony\Component\Serializer\Serializer::class)) {
if (!class_exists(Serializer::class)) {
throw new LogicException('Serializer support cannot be enabled as the Serializer component is not installed. Try running "composer require symfony/serializer-pack".');
}

$this->registerSerializerConfiguration($config['serializer'], $container, $loader);
} else {
$container->register('.argument_resolver.request_payload.no_serializer', Serializer::class)
->addError('You can neither use "#[MapRequestPayload]" nor "#[MapQueryString]" since the Serializer component is not '
.(class_exists(Serializer::class) ? 'enabled. Try setting "framework.serializer" to true.' : 'installed. Try running "composer require symfony/serializer-pack".')
);

$container->getDefinition('argument_resolver.request_payload')
->replaceArgument(0, new Reference('.argument_resolver.request_payload.no_serializer', ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE));
}

if ($propertyInfoEnabled) {
Expand Down
8 changes: 8 additions & 0 deletions 8 src/Symfony/Bundle/FrameworkBundle/Resources/config/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\DateTimeValueResolver;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\DefaultValueResolver;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\RequestAttributeValueResolver;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\RequestPayloadValueResolver;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\RequestValueResolver;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\ServiceValueResolver;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\SessionValueResolver;
Expand Down Expand Up @@ -61,6 +62,13 @@
])
->tag('controller.argument_value_resolver', ['priority' => 100, 'name' => DateTimeValueResolver::class])

->set('argument_resolver.request_payload', RequestPayloadValueResolver::class)
->args([
service('serializer'),
service('validator')->nullOnInvalid(),
])
->tag('controller.targeted_value_resolver', ['name' => RequestPayloadValueResolver::class])

->set('argument_resolver.request_attribute', RequestAttributeValueResolver::class)
->tag('controller.argument_value_resolver', ['priority' => 100, 'name' => RequestAttributeValueResolver::class])

Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.