@@ -50,7 +50,11 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
50
50
*/
51
51
public const DISABLE_TYPE_ENFORCEMENT = 'disable_type_enforcement ' ;
52
52
53
- const SKIP_NULL_VALUES = 'skip_null_values ' ;
53
+ /**
54
+ * Flag to control whether fields with the value `null` should be output
55
+ * when normalizing or omitted.
56
+ */
57
+ public const SKIP_NULL_VALUES = 'skip_null_values ' ;
54
58
55
59
public const MAX_DEPTH_HANDLER = 'max_depth_handler ' ;
56
60
@@ -128,38 +132,38 @@ public function normalize($object, $format = null, array $context = [])
128
132
$ attributesMetadata = $ this ->classMetadataFactory ? $ this ->classMetadataFactory ->getMetadataFor ($ class )->getAttributesMetadata () : null ;
129
133
$ maxDepthHandler = $ context [self ::MAX_DEPTH_HANDLER ] ?? $ this ->defaultContext [self ::MAX_DEPTH_HANDLER ] ?? $ this ->maxDepthHandler ;
130
134
131
- foreach ($ attributes as $ attribute ) {
135
+ foreach ($ attributes as $ attributeName ) {
132
136
$ maxDepthReached = false ;
133
- if (null !== $ attributesMetadata && ($ maxDepthReached = $ this ->isMaxDepthReached ($ attributesMetadata , $ class , $ attribute , $ context )) && !$ maxDepthHandler ) {
137
+ if (null !== $ attributesMetadata && ($ maxDepthReached = $ this ->isMaxDepthReached ($ attributesMetadata , $ class , $ attributeName , $ context )) && !$ maxDepthHandler ) {
134
138
continue ;
135
139
}
136
140
137
- $ attributeValue = $ this ->getAttributeValue ($ object , $ attribute , $ format , $ context );
141
+ $ attributeValue = $ this ->getAttributeValue ($ object , $ attributeName , $ format , $ context );
138
142
if ($ maxDepthReached ) {
139
- $ attributeValue = $ maxDepthHandler ($ attributeValue , $ object , $ attribute , $ format , $ context );
143
+ $ attributeValue = $ maxDepthHandler ($ attributeValue , $ object , $ attributeName , $ format , $ context );
140
144
}
141
145
142
146
/**
143
147
* @var callable|null
144
148
*/
145
- $ callback = $ context [self ::CALLBACKS ][$ attribute ] ?? $ this ->defaultContext [self ::CALLBACKS ][$ attribute ] ?? $ this ->callbacks [$ attribute ] ?? null ;
149
+ $ callback = $ context [self ::CALLBACKS ][$ attributeName ] ?? $ this ->defaultContext [self ::CALLBACKS ][$ attributeName ] ?? $ this ->callbacks [$ attributeName ] ?? null ;
146
150
if ($ callback ) {
147
- $ attributeValue = $ callback ($ attributeValue , $ object , $ attribute , $ format , $ context );
151
+ $ attributeValue = $ callback ($ attributeValue , $ object , $ attributeName , $ format , $ context );
148
152
}
149
153
150
154
if (null !== $ attributeValue && !is_scalar ($ attributeValue )) {
151
- $ stack [$ attribute ] = $ attributeValue ;
155
+ $ stack [$ attributeName ] = $ attributeValue ;
152
156
}
153
157
154
- $ data = $ this ->updateData ($ data , $ attribute , $ attributeValue , $ class , $ format , $ context );
158
+ $ data = $ this ->updateData ($ data , $ attributeName , $ attributeValue , $ class , $ format , $ context );
155
159
}
156
160
157
- foreach ($ stack as $ attribute => $ attributeValue ) {
161
+ foreach ($ stack as $ attributeName => $ attributeValue ) {
158
162
if (!$ this ->serializer instanceof NormalizerInterface) {
159
- throw new LogicException (sprintf ('Cannot normalize attribute "%s" because the injected serializer is not a normalizer ' , $ attribute ));
163
+ throw new LogicException (sprintf ('Cannot normalize attribute "%s" because the injected serializer is not a normalizer ' , $ attributeName ));
160
164
}
161
165
162
- $ data = $ this ->updateData ($ data , $ attribute , $ this ->serializer ->normalize ($ attributeValue , $ format , $ this ->createChildContext ($ context , $ attribute )), $ class , $ format , $ context );
166
+ $ data = $ this ->updateData ($ data , $ attributeName , $ this ->serializer ->normalize ($ attributeValue , $ format , $ this ->createChildContext ($ context , $ attributeName )), $ class , $ format , $ context );
163
167
}
164
168
165
169
return $ data ;
0 commit comments