Skip to content

Commit

Permalink
Merge branch '6.13' into 7.5
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwojs committed Jul 9, 2020
2 parents 935aa52 + 2b87976 commit d3ada07
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function getSerializer(): SerializerInterface
return new Serializer(
[
new CompoundMatcherNormalizer(),
new SimplifiedRequestNormalizer(),
(new PropertyNormalizer())->setIgnoredAttributes(['request', 'container', 'matcherBuilder']),
],
[new JsonEncoder()]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace eZ\Publish\Core\MVC\Symfony\Component\Serializer;

use eZ\Publish\Core\MVC\Symfony\Routing\SimplifiedRequest;
use Symfony\Component\Serializer\Normalizer\PropertyNormalizer;

final class SimplifiedRequestNormalizer extends PropertyNormalizer
{
/**
* @see \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize
*
* @param \eZ\Publish\Core\MVC\Symfony\Routing\SimplifiedRequest $object
*/
public function normalize($object, $format = null, array $context = [])
{
return [
'scheme' => $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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace eZ\Publish\Core\MVC\Symfony\Component\Tests\Serializer;

use eZ\Publish\Core\MVC\Symfony\Component\Serializer\SimplifiedRequestNormalizer;
use eZ\Publish\Core\MVC\Symfony\Routing\SimplifiedRequest;
use PHPUnit\Framework\TestCase;
use stdClass;

final class SimplifiedRequestNormalizerTest extends TestCase
{
public function testNormalize()
{
$request = new SimplifiedRequest([
'scheme' => '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()));
}
}

0 comments on commit d3ada07

Please sign in to comment.