File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 44
55- Default throttles for rate limiting have been removed.
66
7+ #### Fixed
8+
9+ - Fixed bug where any response object that could not be type cast as a string would throw an ` UnexpectedValueException ` .
10+
711### v0.7.2
812
913#### Fixed
Original file line number Diff line number Diff line change 33namespace Dingo \Api \Http ;
44
55use ArrayObject ;
6+ use UnexpectedValueException ;
67use Dingo \Api \Transformer \TransformerFactory ;
78use Illuminate \Http \Response as IlluminateResponse ;
89use Illuminate \Support \Contracts \ArrayableInterface ;
@@ -72,6 +73,24 @@ public function morph($format = 'json')
7273 return $ this ;
7374 }
7475
76+ /**
77+ * {@inheritDoc}
78+ */
79+ public function setContent ($ content )
80+ {
81+ // Attempt to set the content string, if we encounter an unexpected value
82+ // then we most likely have an object that cannot be type cast. In that
83+ // case we'll simply leave the content as null and set the original
84+ // content value the continue.
85+ try {
86+ return parent ::setContent ($ content );
87+ } catch (UnexpectedValueException $ exception ) {
88+ $ this ->original = $ content ;
89+
90+ return $ this ;
91+ }
92+ }
93+
7594 /**
7695 * Get the formatter based on the requested format type.
7796 *
Original file line number Diff line number Diff line change 22
33namespace Dingo \Api \Tests \Http ;
44
5+ use stdClass ;
56use Dingo \Api \Http \Response ;
67use PHPUnit_Framework_TestCase ;
78
@@ -15,4 +16,16 @@ public function testGettingInvalidFormatterThrowsException()
1516 {
1617 Response::getFormatter ('json ' );
1718 }
19+
20+
21+ public function testNonCastableObjectsSetAsOriginalContent ()
22+ {
23+ $ object = new stdClass ;
24+ $ object ->id = 'test ' ;
25+
26+ $ response = new Response ($ object );
27+
28+ $ this ->assertNull ($ response ->getContent ());
29+ $ this ->assertSame ($ object , $ response ->getOriginalContent ());
30+ }
1831}
You can’t perform that action at this time.
0 commit comments