File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -352,6 +352,9 @@ protected function makeResponseBodyPart(mixed $result) : string
352
352
$ this ->router ->getResponse ()->setJson ($ result );
353
353
return '' ;
354
354
}
355
+ if (\is_object ($ result ) && \method_exists ($ result , '__toString ' )) {
356
+ return (string ) $ result ;
357
+ }
355
358
$ type = \get_debug_type ($ result );
356
359
throw new RoutingException (
357
360
"Invalid action return type ' {$ type }' " . $ this ->onNamedRoutePart ()
Original file line number Diff line number Diff line change @@ -286,6 +286,25 @@ static function () {
286
286
self ::assertSame ('1.5 ' , $ this ->response ->getBody ());
287
287
}
288
288
289
+ public function testResponseBodyPartWithStringable () : void
290
+ {
291
+ $ route = new Route (
292
+ $ this ->router ,
293
+ 'http://domain.tld ' ,
294
+ '/ ' ,
295
+ static function () {
296
+ return new class () {
297
+ public function __toString () : string
298
+ {
299
+ return '__toString ' ;
300
+ }
301
+ };
302
+ }
303
+ );
304
+ self ::assertInstanceOf (Response::class, $ route ->run ());
305
+ self ::assertSame ('__toString ' , $ this ->response ->getBody ());
306
+ }
307
+
289
308
public function testResponseBodyPartWithJsonSerializable () : void
290
309
{
291
310
$ data = ['id ' => 1 , 'name ' => 'Natan ' ];
You can’t perform that action at this time.
0 commit comments