diff --git a/eZ/Publish/Core/MVC/Symfony/Component/Serializer/SerializerTrait.php b/eZ/Publish/Core/MVC/Symfony/Component/Serializer/SerializerTrait.php index 6ea71638cc2..ba0cf330883 100644 --- a/eZ/Publish/Core/MVC/Symfony/Component/Serializer/SerializerTrait.php +++ b/eZ/Publish/Core/MVC/Symfony/Component/Serializer/SerializerTrait.php @@ -20,6 +20,7 @@ public function getSerializer() return new Serializer( [ new CompoundMatcherNormalizer(), + new SimplifiedRequestNormalizer(), (new PropertyNormalizer())->setIgnoredAttributes(['request', 'container', 'matcherBuilder']), ], [new JsonEncoder()] diff --git a/eZ/Publish/Core/MVC/Symfony/Component/Serializer/SimplifiedRequestNormalizer.php b/eZ/Publish/Core/MVC/Symfony/Component/Serializer/SimplifiedRequestNormalizer.php new file mode 100644 index 00000000000..7911f55f554 --- /dev/null +++ b/eZ/Publish/Core/MVC/Symfony/Component/Serializer/SimplifiedRequestNormalizer.php @@ -0,0 +1,36 @@ + $object->scheme, + 'host' => $object->host, + 'port' => $object->port, + 'pathinfo' => $object->pathinfo, + 'queryParams' => $object->queryParams, + 'languages' => $object->languages, + 'headers' => [], + ]; + } + + public function supportsNormalization($data, $format = null, array $context = []) + { + return $data instanceof SimplifiedRequest; + } +} diff --git a/eZ/Publish/Core/MVC/Symfony/Component/Tests/Serializer/SimplifiedRequestNormalizerTest.php b/eZ/Publish/Core/MVC/Symfony/Component/Tests/Serializer/SimplifiedRequestNormalizerTest.php new file mode 100644 index 00000000000..18ddbb88c73 --- /dev/null +++ b/eZ/Publish/Core/MVC/Symfony/Component/Tests/Serializer/SimplifiedRequestNormalizerTest.php @@ -0,0 +1,55 @@ + 'http', + 'host' => 'www.example.com', + 'port' => 8080, + 'pathinfo' => '/foo', + 'queryParams' => ['param' => 'value', 'this' => 'that'], + 'headers' => [ + 'Accept' => 'text/html,application/xhtml+xml', + 'Accept-Encoding' => 'gzip, deflate, br', + 'Accept-Language' => 'pl-PL,pl;q=0.9,en-US;q=0.8,en;q=0.7', + 'User-Agent' => 'Mozilla/5.0', + 'Cookie' => 'eZSESSID21232f297a57a5a743894a0e4a801fc3=mgbs2p6lv936hb5hmdd2cvq6bq', + 'Connection' => 'keep-alive', + ], + 'languages' => ['pl-PL', 'en-US'], + ]); + + $normalizer = new SimplifiedRequestNormalizer(); + + $this->assertEquals([ + 'scheme' => 'http', + 'host' => 'www.example.com', + 'port' => 8080, + 'pathinfo' => '/foo', + 'queryParams' => ['param' => 'value', 'this' => 'that'], + 'headers' => [], + 'languages' => ['pl-PL', 'en-US'], + ], $normalizer->normalize($request)); + } + + public function testSupportsNormalization() + { + $normalizer = new SimplifiedRequestNormalizer(); + + $this->assertTrue($normalizer->supportsNormalization(new SimplifiedRequest())); + $this->assertFalse($normalizer->supportsNormalization(new stdClass())); + } +}