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

Commit8566dc1

Browse files
committed
Remove normalizer cache in Serializer class
1 parent06eec9d commit8566dc1

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ private function normalizeObject($object, $format = null, array $context = array
237237
foreach ($this->normalizersas$normalizer) {
238238
if ($normalizerinstanceof NormalizerInterface
239239
&&$normalizer->supportsNormalization($object,$format)) {
240-
$this->normalizerCache[$class][$format] =$normalizer;
241240

242241
return$normalizer->normalize($object,$format,$context);
243242
}
@@ -272,7 +271,6 @@ private function denormalizeObject($data, $class, $format = null, array $context
272271
foreach ($this->normalizersas$normalizer) {
273272
if ($normalizerinstanceof DenormalizerInterface
274273
&&$normalizer->supportsDenormalization($data,$class,$format)) {
275-
$this->denormalizerCache[$class][$format] =$normalizer;
276274

277275
return$normalizer->denormalize($data,$class,$format,$context);
278276
}

‎src/Symfony/Component/Serializer/Tests/SerializerTest.php‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,50 @@ public function testDenormalizeOnNormalizer()
7373
$this->assertTrue($this->serializer->denormalize(json_encode($data),'stdClass','json'));
7474
}
7575

76+
publicfunctiontestNormalizeWithSupportOnData()
77+
{
78+
$normalizer1 =$this->getMock('Symfony\Component\Serializer\Normalizer\NormalizerInterface');
79+
$normalizer1->method('supportsNormalization')
80+
->willReturnCallback(function ($data,$format) {
81+
returnisset($data->test);
82+
});
83+
$normalizer1->method('normalize')->willReturn('test1');
84+
85+
$normalizer2 =$this->getMock('Symfony\Component\Serializer\Normalizer\NormalizerInterface');
86+
$normalizer2->method('supportsNormalization')
87+
->willReturn(true);
88+
$normalizer2->method('normalize')->willReturn('test2');
89+
90+
$serializer =newSerializer(array($normalizer1,$normalizer2));
91+
92+
$data =new \stdClass();
93+
$data->test =true;
94+
$this->assertEquals('test1',$serializer->normalize($data));
95+
96+
$this->assertEquals('test2',$serializer->normalize(new \stdClass()));
97+
}
98+
99+
publicfunctiontestDenormalizeWithSupportOnData()
100+
{
101+
$denormalizer1 =$this->getMock('Symfony\Component\Serializer\Normalizer\DenormalizerInterface');
102+
$denormalizer1->method('supportsDenormalization')
103+
->willReturnCallback(function ($data,$type,$format) {
104+
returnisset($data['test1']);
105+
});
106+
$denormalizer1->method('denormalize')->willReturn('test1');
107+
108+
$denormalizer2 =$this->getMock('Symfony\Component\Serializer\Normalizer\DenormalizerInterface');
109+
$denormalizer2->method('supportsDenormalization')
110+
->willReturn(true);
111+
$denormalizer2->method('denormalize')->willReturn('test2');
112+
113+
$serializer =newSerializer(array($denormalizer1,$denormalizer2));
114+
115+
$this->assertEquals('test1',$serializer->denormalize(array('test1' =>true),'test'));
116+
117+
$this->assertEquals('test2',$serializer->denormalize(array(),'test'));
118+
}
119+
76120
publicfunctiontestSerialize()
77121
{
78122
$this->serializer =newSerializer(array(newGetSetMethodNormalizer()),array('json' =>newJsonEncoder()));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp