-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
eZ/Publish/Core/MVC/Symfony/Component/Serializer/SimplifiedRequestNormalizer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
eZ/Publish/Core/MVC/Symfony/Component/Tests/Serializer/SimplifiedRequestNormalizerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
} |