@@ -34,6 +34,13 @@ class Response extends IlluminateResponse
34
34
*/
35
35
protected $ binding ;
36
36
37
+ /**
38
+ * Intermedia content that we are working on. The result content should be a string (symfony)
39
+ * )
40
+ * @var mixed Content with which we are working
41
+ */
42
+ protected $ workingContent ;
43
+
37
44
/**
38
45
* Array of registered formatters.
39
46
*
@@ -125,12 +132,12 @@ public static function makeFromJson(JsonResponse $json)
125
132
*/
126
133
public function morph ($ format = 'json ' )
127
134
{
128
- $ content = $ this ->getOriginalContent () ?? '' ;
135
+ $ this -> workingContent = $ this ->getOriginalContent () ?? '' ;
129
136
130
137
$ this ->fireMorphingEvent ();
131
138
132
- if (isset (static ::$ transformer ) && static ::$ transformer ->transformableResponse ($ content )) {
133
- $ content = static ::$ transformer ->transform ($ content );
139
+ if (isset (static ::$ transformer ) && static ::$ transformer ->transformableResponse ($ this -> workingContent )) {
140
+ $ this -> workingContent = static ::$ transformer ->transform ($ this -> workingContent );
134
141
}
135
142
136
143
$ formatter = static ::getFormatter ($ format );
@@ -147,21 +154,21 @@ public function morph($format = 'json')
147
154
148
155
$ this ->fireMorphedEvent ();
149
156
150
- if ($ content instanceof EloquentModel) {
151
- $ content = $ formatter ->formatEloquentModel ($ content );
152
- } elseif ($ content instanceof EloquentCollection) {
153
- $ content = $ formatter ->formatEloquentCollection ($ content );
154
- } elseif (is_array ($ content ) || $ content instanceof ArrayObject || $ content instanceof Arrayable) {
155
- $ content = $ formatter ->formatArray ($ content );
156
- } elseif ($ content instanceof stdClass) {
157
- $ content = $ formatter ->formatArray ((array ) $ content );
157
+ if ($ this -> workingContent instanceof EloquentModel) {
158
+ $ this -> workingContent = $ formatter ->formatEloquentModel ($ this -> workingContent );
159
+ } elseif ($ this -> workingContent instanceof EloquentCollection) {
160
+ $ this -> workingContent = $ formatter ->formatEloquentCollection ($ this -> workingContent );
161
+ } elseif (is_array ($ this -> workingContent ) || $ this -> workingContent instanceof ArrayObject || $ this -> workingContent instanceof Arrayable) {
162
+ $ this -> workingContent = $ formatter ->formatArray ($ this -> workingContent );
163
+ } elseif ($ this -> workingContent instanceof stdClass) {
164
+ $ this -> workingContent = $ formatter ->formatArray ((array ) $ this -> workingContent );
158
165
} else {
159
166
if (! empty ($ defaultContentType )) {
160
167
$ this ->headers ->set ('Content-Type ' , $ defaultContentType );
161
168
}
162
169
}
163
170
164
- $ this ->content = $ content ;
171
+ $ this ->content = $ this -> workingContent ;
165
172
166
173
return $ this ;
167
174
}
@@ -177,7 +184,7 @@ protected function fireMorphedEvent()
177
184
return ;
178
185
}
179
186
180
- static ::$ events ->dispatch (new ResponseWasMorphed ($ this , $ this ->content ));
187
+ static ::$ events ->dispatch (new ResponseWasMorphed ($ this , $ this ->workingContent ));
181
188
}
182
189
183
190
/**
@@ -191,7 +198,7 @@ protected function fireMorphingEvent()
191
198
return ;
192
199
}
193
200
194
- static ::$ events ->dispatch (new ResponseIsMorphing ($ this , $ this ->content ));
201
+ static ::$ events ->dispatch (new ResponseIsMorphing ($ this , $ this ->workingContent ));
195
202
}
196
203
197
204
/**
0 commit comments