Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit60ee9ed

Browse files
author
Rokas Mikalkėnas
committed
[Serializer] Support canners in object normalizer
1 parentabd7a2c commit60ee9ed

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

‎src/Symfony/Component/Serializer/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CHANGELOG
1010
* Deprecate`ContextAwareDenormalizerInterface`, use`DenormalizerInterface` instead
1111
* Deprecate`ContextAwareEncoderInterface`, use`EncoderInterface` instead
1212
* Deprecate`ContextAwareDecoderInterface`, use`DecoderInterface` instead
13+
* Add support for`can*()` methods to`ObjectNormalizer`
1314

1415
6.0
1516
---

‎src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ protected function extractAttributes(object $object, string $format = null, arra
8686
$name =$reflMethod->name;
8787
$attributeName =null;
8888

89-
if (str_starts_with($name,'get') ||str_starts_with($name,'has')) {
90-
// gettersandhassers
89+
if (str_starts_with($name,'get') ||str_starts_with($name,'has') ||str_starts_with($name,'can')) {
90+
// getters, hassersandcanners
9191
$attributeName =substr($name,3);
9292

9393
if (!$reflClass->hasProperty($attributeName)) {

‎src/Symfony/Component/Serializer/Tests/Normalizer/Features/ObjectDummy.php‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class ObjectDummy
1212
private$baz;
1313
protected$camelCase;
1414
protected$object;
15+
private$go;
1516

1617
publicfunctiongetFoo()
1718
{
@@ -62,4 +63,14 @@ public function getObject()
6263
{
6364
return$this->object;
6465
}
66+
67+
publicfunctionsetGo($go)
68+
{
69+
$this->go =$go;
70+
}
71+
72+
publicfunctioncanGo()
73+
{
74+
return$this->go;
75+
}
6576
}

‎src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public function testNormalize()
107107
$obj->setBaz(true);
108108
$obj->setCamelCase('camelcase');
109109
$obj->setObject($object);
110+
$obj->setGo(true);
110111

111112
$this->serializer
112113
->expects($this->once())
@@ -123,6 +124,7 @@ public function testNormalize()
123124
'fooBar' =>'foobar',
124125
'camelCase' =>'camelcase',
125126
'object' =>'string_object',
127+
'go' =>true,
126128
],
127129
$this->normalizer->normalize($obj,'any')
128130
);
@@ -664,6 +666,7 @@ public function testNormalizeNotSerializableContext()
664666
'camelCase' =>null,
665667
'object' =>null,
666668
'bar' =>null,
669+
'go' =>null,
667670
];
668671

669672
$this->assertEquals($expected,$this->normalizer->normalize($objectDummy,null, ['not_serializable' =>function () {
@@ -800,6 +803,7 @@ public function testDefaultObjectClassResolver()
800803
$obj->setBaz(true);
801804
$obj->setCamelCase('camelcase');
802805
$obj->unwantedProperty ='notwanted';
806+
$obj->setGo(false);
803807

804808
$this->assertEquals(
805809
[
@@ -809,6 +813,7 @@ public function testDefaultObjectClassResolver()
809813
'fooBar' =>'foobar',
810814
'camelCase' =>'camelcase',
811815
'object' =>null,
816+
'go' =>false,
812817
],
813818
$normalizer->normalize($obj,'any')
814819
);
@@ -837,6 +842,7 @@ public function testObjectClassResolver()
837842
'fooBar' =>'foobar',
838843
'camelCase' =>'camelcase',
839844
'object' =>null,
845+
'go' =>null,
840846
],
841847
$normalizer->normalize($obj,'any')
842848
);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp