@@ -117,7 +117,12 @@ public function getReasonPhrase()
117117 */
118118 public function withCookie (Cookie $ cookie ): self
119119 {
120- $ this ->setResponse ($ this ->getResponse ()->withCookie ($ cookie ));
120+ $ response = $ this ->getResponse ();
121+ if (! method_exists ($ response , 'withCookie ' )) {
122+ throw new RuntimeException ('Method withCookie is invalid. ' );
123+ }
124+
125+ $ this ->setResponse ($ response ->withCookie ($ cookie ));
121126 return $ this ;
122127 }
123128
@@ -126,7 +131,11 @@ public function withCookie(Cookie $cookie): self
126131 */
127132 public function getCookies (): array
128133 {
129- return $ this ->getResponse ()->getCookies ();
134+ $ response = $ this ->getResponse ();
135+ if (! method_exists ($ response , 'getCookies ' )) {
136+ throw new RuntimeException ('Method getCookies is invalid. ' );
137+ }
138+ return $ response ->getCookies ();
130139 }
131140
132141 /**
@@ -135,7 +144,11 @@ public function getCookies(): array
135144 */
136145 public function withTrailer (string $ key , $ value ): self
137146 {
138- $ this ->setResponse ($ this ->getResponse ()->withTrailer ($ key , $ value ));
147+ $ response = $ this ->getResponse ();
148+ if (! method_exists ($ response , 'withTrailer ' )) {
149+ throw new RuntimeException ('Method withTrailer is invalid. ' );
150+ }
151+ $ this ->setResponse ($ response ->withTrailer ($ key , $ value ));
139152 return $ this ;
140153 }
141154
@@ -144,14 +157,22 @@ public function withTrailer(string $key, $value): self
144157 */
145158 public function getTrailer (string $ key )
146159 {
147- return $ this ->getResponse ()->getTrailer ($ key );
160+ $ response = $ this ->getResponse ();
161+ if (! method_exists ($ response , 'getTrailer ' )) {
162+ throw new RuntimeException ('Method getTrailer is invalid. ' );
163+ }
164+ return $ response ->getTrailer ($ key );
148165 }
149166
150167 /**
151168 * Retrieves all trailers values.
152169 */
153170 public function getTrailers (): array
154171 {
155- return $ this ->getResponse ()->getTrailers ();
172+ $ response = $ this ->getResponse ();
173+ if (! method_exists ($ response , 'getTrailers ' )) {
174+ throw new RuntimeException ('Method getTrailers is invalid. ' );
175+ }
176+ return $ response ->getTrailers ();
156177 }
157178}
0 commit comments