8000 [serializer] validate that the specified callbacks are actually callable · symfony/symfony@ba1097c · GitHub
[go: up one dir, main page]

Skip to content
10000

Commit ba1097c

Browse files
dbujewome62
authored andcommitted
[serializer] validate that the specified callbacks are actually callable
1 parent ecb52bc commit ba1097c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ public function __construct(ClassMetadataFactoryInterface $classMetadataFactory
9999
$this->nameConverter = $nameConverter;
100100
$this->defaultContext = array_merge($this->defaultContext, $defaultContext);
101101

102-
if (\is_array($this->defaultContext[self::CALLBACKS] ?? null)) {
102+
if (\array_key_exists(self::CALLBACKS, $this->defaultContext)) {
103103
foreach ($this->defaultContext[self::CALLBACKS] as $attribute => $callback) {
104104
if (!\is_callable($callback)) {
105-
throw new InvalidArgumentException(sprintf('The given callback for attribute "%s" is not callable.', $attribute));
105+
throw new InvalidArgumentException(sprintf('The callback given in the default context for attribute "%s" is not callable.', $attribute));
106106
}
107107
}
108108
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ public function normalize($object, $format = null, array $context = [])
8686
if (!isset($context['cache_key'])) {
8787
$context['cache_key'] = $this->getCacheKey($format, $context);
8888
}
89+
if (\array_key_exists(self::CALLBACKS, $context)) {
90+
foreach ($context[self::CALLBACKS] as $attribute => $callback) {
91+
if (!\is_callable($callback)) {
92+
throw new InvalidArgumentException(sprintf('The callback given in the context for attribute "%s" is not callable.', $attribute));
93+
}
94+
}
95+
}
8996

9097
if ($this->isCircularReference($object, $context)) {
9198
return $this->handleCircularReference($object, $format, $context);

0 commit comments

Comments
 (0)
0