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

Skip to content

Commit 5863e4b

Browse files
committed
minor #22555 [Serializer] Add missing normalizer options constants (ogizanagi)
This PR was merged into the 3.3-dev branch. Discussion ---------- [Serializer] Add missing normalizer options constants | Q | A | ------------- | --- | Branch? | master (3.3) | Bug fix? | not really | New feature? | yesish, but for 3.3 as those options were added on this branch and not released yet | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22537 (comment) | License | MIT | Doc PR | N/A As seen in #22537 (comment). @dunglas : I'm not sure about the exposing the `key_type` option as a constant in `ArrayDenormalizer`/`AbstractObjectNormalizer`, as it looks more or less like a detail of the AbstractObjectNormalizer implementation, but anyway it should be in 3.2 if we add it, so I haven't included it here. However, I wonder if this option shouldn't directly accept a string too, rather than just a `Symfony\Component\PropertyInfo\Type` instance if we want to consider this option "public"? Commits ------- b0c414f [Serializer] Add missing normalizer options constants
2 parents 1cef186 + b0c414f commit 5863e4b

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
3030
const CIRCULAR_REFERENCE_LIMIT = 'circular_reference_limit';
3131
const OBJECT_TO_POPULATE = 'object_to_populate';
3232
const GROUPS = 'groups';
33+
const ATTRIBUTES = 'attributes';
3334

3435
/**
3536
* @var int
@@ -240,13 +241,13 @@ protected function isAllowedAttribute($classOrObject, $attribute, $format = null
240241
return false;
241242
}
242243

243-
if (isset($context['attributes'][$attribute])) {
244+
if (isset($context[self::ATTRIBUTES][$attribute])) {
244245
// Nested attributes
245246
return true;
246247
}
247248

248-
if (isset($context['attributes']) && is_array($context['attributes'])) {
249-
return in_array($attribute, $context['attributes'], true);
249+
if (isset($context[self::ATTRIBUTES]) && is_array($context[self::ATTRIBUTES])) {
250+
return in_array($attribute, $context[self::ATTRIBUTES], true);
250251
}
251252

252253
return true;
@@ -396,8 +397,8 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
396397
*/
397398
protected function createChildContext(array $parentContext, $attribute)
398399
{
399-
if (isset($parentContext['attributes'][$attribute])) {
400-
$parentContext['attributes'] = $parentContext['attributes'][$attribute];
400+
if (isset($parentContext[self::ATTRIBUTES][$attribute])) {
401+
$parentContext[self::ATTRIBUTES] = $parentContext[self::ATTRIBUTES][$attribute];
401402
}
402403

403404
return $parentContext;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
3232
{
3333
const ENABLE_MAX_DEPTH = 'enable_max_depth';
3434
const DEPTH_KEY_PATTERN = 'depth_%s::%s';
35+
const ALLOW_EXTRA_ATTRIBUTES = 'allow_extra_attributes';
3536

3637
private $propertyTypeExtractor;
3738
private $attributesCache = array();
@@ -189,7 +190,7 @@ public function denormalize($data, $class, $format = null, array $context = arra
189190
}
190191

191192
if (($allowedAttributes !== false && !in_array($attribute, $allowedAttributes)) || !$this->isAllowedAttribute($class, $attribute, $format, $context)) {
192-
if (isset($context['allow_extra_attributes']) && !$context['allow_extra_attributes']) {
193+
if (isset($context[self::ALLOW_EXTRA_ATTRIBUTES]) && !$context[self::ALLOW_EXTRA_ATTRIBUTES]) {
193194
$extraAttributes[] = $attribute;
194195
}
195196

0 commit comments

Comments
 (0)