@@ -61,7 +61,7 @@ class {$context['class']} implements NormalizerInterface, NormalizerAwareInterfa
61
61
62
62
use CircularReferenceTrait, NormalizerAwareTrait;
63
63
64
- public function __construct(array \$defaultContext)
64
+ public function __construct(array \$defaultContext = array() )
65
65
{
66
66
\$this->defaultContext = array_merge( \$this->defaultContext, \$defaultContext);
67
67
}
@@ -91,7 +91,7 @@ private function generateNormalizeMethodInner(\ReflectionClass $reflectionClass)
91
91
$ code = <<<EOL
92
92
93
93
if ( \$this->isCircularReference( \$object, \$context)) {
94
- return \$this->handleCircularReference( \$object);
94
+ return \$this->handleCircularReference( \$object, \$ format, \$ context );
95
95
}
96
96
97
97
\$groups = isset( \$context[ObjectNormalizer::GROUPS]) && is_array( \$context[ObjectNormalizer::GROUPS]) ? \$context[ObjectNormalizer::GROUPS] : null;
@@ -113,10 +113,9 @@ private function generateNormalizeMethodInner(\ReflectionClass $reflectionClass)
113
113
}
114
114
115
115
if ($ maxDepthCode ) {
116
- $ maxDepthKey = ObjectNormalizer::ENABLE_MAX_DEPTH ;
117
116
$ code .= <<<EOL
118
117
119
- if ( \$context[ $ maxDepthKey ] ?? \$this->defaultContext[ $ maxDepthKey ]) { {$ maxDepthCode }
118
+ if ( \$context[ObjectNormalizer::ENABLE_MAX_DEPTH ] ?? \$this->defaultContext[ObjectNormalizer::ENABLE_MAX_DEPTH ]) { {$ maxDepthCode }
120
119
}
121
120
122
121
EOL ;
@@ -125,7 +124,7 @@ private function generateNormalizeMethodInner(\ReflectionClass $reflectionClass)
125
124
foreach ($ attributesMetadata as $ attributeMetadata ) {
126
125
$ code .= <<<EOL
127
126
128
- \$attributes = \$context['attributes' ] ?? $ this ->defaultContext ['attributes' ] ?? null
127
+ \$attributes = \$context[ObjectNormalizer::ATTRIBUTES ] ?? \ $this->defaultContext[ObjectNormalizer::ATTRIBUTES ] ?? null;
129
128
if ((null === \$groups
130
129
EOL ;
131
130
@@ -134,7 +133,7 @@ private function generateNormalizeMethodInner(\ReflectionClass $reflectionClass)
134
133
}
135
134
$ code .= ') ' ;
136
135
137
- $ code .= " && (isset( \$attributes[' {$ attributeMetadata ->name }']) || (is_array( \$attributes) && in_array(' {$ attributeMetadata ->name }', \$attributes, true))) " ;
136
+ $ code .= " && (null === \$ attributes || isset( \$attributes[' {$ attributeMetadata ->name }']) || (is_array( \$attributes) && in_array(' {$ attributeMetadata ->name }', \$attributes, true))) " ;
138
137
139
138
if (null !== $ maxDepth = $ attributeMetadata ->getMaxDepth ()) {
140
139
$ key = sprintf (ObjectNormalizer::DEPTH_KEY_PATTERN , $ reflectionClass ->name , $ attributeMetadata ->name );
@@ -151,10 +150,10 @@ private function generateNormalizeMethodInner(\ReflectionClass $reflectionClass)
151
150
\$output[' {$ attributeMetadata ->name }'] = \$value;
152
151
} else {
153
152
\$subContext = \$context;
154
- if (isset( \$context[' attributes'] [' {$ attributeMetadata ->name }'])) {
155
- \$subContext['attributes' ] = \$context[' attributes'] [' {$ attributeMetadata ->name }'];
153
+ if (isset( \$attributes[' {$ attributeMetadata ->name }'])) {
154
+ \$subContext[ObjectNormalizer::ATTRIBUTES ] = \$attributes[' {$ attributeMetadata ->name }'];
156
155
} else {
157
- unset( \$subContext['attributes' ]);
156
+ unset( \$subContext[ObjectNormalizer::ATTRIBUTES ]);
158
157
}
159
158
160
159
\$output[' {$ attributeMetadata ->name }'] = \$this->normalizer->normalize( \$value, \$format, \$subContext);
0 commit comments