Skip to content

[Serializer] Add missing normalizer options constants #22555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
const CIRCULAR_REFERENCE_LIMIT = 'circular_reference_limit';
const OBJECT_TO_POPULATE = 'object_to_populate';
const GROUPS = 'groups';
const ATTRIBUTES = 'attributes';

/**
* @var int
Expand Down Expand Up @@ -240,13 +241,13 @@ protected function isAllowedAttribute($classOrObject, $attribute, $format = null
return false;
}

if (isset($context['attributes'][$attribute])) {
if (isset($context[self::ATTRIBUTES][$attribute])) {
// Nested attributes
return true;
}

if (isset($context['attributes']) && is_array($context['attributes'])) {
return in_array($attribute, $context['attributes'], true);
if (isset($context[self::ATTRIBUTES]) && is_array($context[self::ATTRIBUTES])) {
return in_array($attribute, $context[self::ATTRIBUTES], true);
}

return true;
Expand Down Expand Up @@ -396,8 +397,8 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
*/
protected function createChildContext(array $parentContext, $attribute)
{
if (isset($parentContext['attributes'][$attribute])) {
$parentContext['attributes'] = $parentContext['attributes'][$attribute];
if (isset($parentContext[self::ATTRIBUTES][$attribute])) {
$parentContext[self::ATTRIBUTES] = $parentContext[self::ATTRIBUTES][$attribute];
}

return $parentContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
{
const ENABLE_MAX_DEPTH = 'enable_max_depth';
const DEPTH_KEY_PATTERN = 'depth_%s::%s';
const ALLOW_EXTRA_ATTRIBUTES = 'allow_extra_attributes';

private $propertyTypeExtractor;
private $attributesCache = array();
Expand Down Expand Up @@ -189,7 +190,7 @@ public function denormalize($data, $class, $format = null, array $context = arra
}

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

Expand Down