Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b7e8a89

Browse files
committed
[Serializer] Allow to pass a single value for the groups opt
1 parent 4cd6477 commit b7e8a89

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ protected function getAllowedAttributes($classOrObject, array $context, $attribu
221221
}
222222

223223
$groups = false;
224-
if (isset($context[static::GROUPS]) && \is_array($context[static::GROUPS])) {
225-
$groups = $context[static::GROUPS];
224+
if (isset($context[static::GROUPS])) {
225+
$groups = (array) $context[static::GROUPS];
226226
} elseif (!isset($context[static::ALLOW_EXTRA_ATTRIBUTES]) || $context[static::ALLOW_EXTRA_ATTRIBUTES]) {
227227
return false;
228228
}

src/Symfony/Component/Serializer/Tests/Normalizer/AbstractNormalizerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ public function testGetAllowedAttributesAsObjects()
9292
$result = $this->normalizer->getAllowedAttributes('c', array(AbstractNormalizer::GROUPS => array('test')), false);
9393
$this->assertEquals(array($a2, $a4), $result);
9494

95+
$result = $this->normalizer->getAllowedAttributes('c', array(AbstractNormalizer::GROUPS => 'test'), false);
96+
$this->assertEquals(array($a2, $a4), $result);
97+
9598
$result = $this->normalizer->getAllowedAttributes('c', array(AbstractNormalizer::GROUPS => array('other')), false);
9699
$this->assertEquals(array($a3, $a4), $result);
97100
}

0 commit comments

Comments
 (0)