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

Commitea24bfc

Browse files
committed
[Serializer] Catch \Throwable in getCacheKey()
1 parent5da141b commitea24bfc

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,20 @@ protected function createChildContext(array $parentContext, $attribute/*, string
401401
privatefunctiongetCacheKey($format,array$context)
402402
{
403403
unset($context['cache_key']);// avoid artificially different keys
404+
405+
if (interface_exists(\Throwable::class)) {
406+
try {
407+
returnmd5($format.serialize([
408+
'context' =>$context,
409+
'ignored' =>$this->ignoredAttributes,
410+
'camelized' =>$this->camelizedAttributes,
411+
]));
412+
}catch (\Throwable$exception) {
413+
// The context cannot be serialized, skip the cache
414+
returnfalse;
415+
}
416+
}
417+
404418
try {
405419
returnmd5($format.serialize([
406420
'context' =>$context,

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,13 @@ public function testExtraAttributesException()
194194
'allow_extra_attributes' =>false,
195195
]);
196196
}
197+
198+
publicfunctiontestContextNotSerializable()
199+
{
200+
$normalizer =newObjectNormalizer();
201+
$result =$normalizer->normalize(newDummy(),null, ['not_serializable' =>newNotSerializable()]);
202+
$this->assertIsArray($result);
203+
}
197204
}
198205

199206
class AbstractObjectNormalizerDummyextends AbstractObjectNormalizer
@@ -379,3 +386,15 @@ public function setSerializer(SerializerInterface $serializer)
379386
$this->serializer =$serializer;
380387
}
381388
}
389+
390+
class NotSerializable
391+
{
392+
function__sleep()
393+
{
394+
if (class_exists(\Error::class)) {
395+
thrownew \Error('not serializable');
396+
}
397+
398+
thrownew \Exception('not serializable');
399+
}
400+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp