12
12
use Joomla \Filesystem \File ;
13
13
use Joomla \Filesystem \Folder ;
14
14
use Joomla \Filesystem \Path ;
15
+ use Joomla \Http \Response as HttpResponse ;
15
16
16
17
/**
17
18
* AI response data object class.
18
19
*
19
20
* @since __DEPLOY_VERSION__
20
21
*/
21
- class Response
22
+ class Response extends HttpResponse
22
23
{
23
24
/**
24
- * The content of the response.
25
+ * The provider of the response.
25
26
*
26
27
* @var string
27
28
* @since __DEPLOY_VERSION__
28
29
*/
29
- private $ content ;
30
-
31
- /**
32
- * The status code of the response.
33
- *
34
- * @var int
35
- * @since __DEPLOY_VERSION__
36
- */
37
- private $ statusCode ;
30
+ private string $ provider ;
38
31
39
32
/**
40
33
* The metadata of the response.
41
34
*
42
35
* @var array
43
36
* @since __DEPLOY_VERSION__
44
37
*/
45
- private $ metadata ;
46
-
47
- /**
48
- * The provider of the response.
49
- *
50
- * @var string
51
- * @since __DEPLOY_VERSION__
52
- */
53
- private $ provider ;
38
+ private array $ metadata ;
54
39
55
40
/**
56
41
* Constructor.
@@ -64,21 +49,25 @@ class Response
64
49
*/
65
50
public function __construct (string $ content , string $ provider , array $ metadata = [], int $ status = 200 )
66
51
{
67
- $ this ->content = $ content ;
52
+ parent ::__construct ('php://memory ' , $ status );
53
+
54
+ $ body = $ this ->getBody ();
55
+ $ body ->write ($ content );
56
+ $ body ->rewind ();
57
+
68
58
$ this ->provider = $ provider ;
69
59
$ this ->metadata = $ metadata ;
70
- $ this ->statusCode = $ status ;
71
60
}
72
61
73
62
/**
74
63
* Get the content of the response.
75
64
*
76
- * @return string The content of the response.
65
+ * @return string
77
66
* @since __DEPLOY_VERSION__
78
67
*/
79
68
public function getContent (): string
80
69
{
81
- return $ this ->content ;
70
+ return ( string ) $ this ->getBody () ;
82
71
}
83
72
84
73
/**
@@ -191,55 +180,4 @@ public function getProvider(): string
191
180
{
192
181
return $ this ->provider ;
193
182
}
194
-
195
- /**
196
- * Get the status code of the response.
197
- *
198
- * @return int The status code of the response.
199
- * @since __DEPLOY_VERSION__
200
- */
201
- public function getStatusCode (): int
202
- {
203
- return $ this ->statusCode ;
204
- }
205
-
206
- /**
207
- * Magic method to access properties of the response object.
208
- *
209
- * @param string $name The name of the property to get.
210
- *
211
- * @return mixed The value of the property.
212
- * @since __DEPLOY_VERSION__
213
- */
214
- public function __get ($ name )
215
- {
216
- switch (strtolower ($ name )) {
217
- case 'content ' :
218
- return $ this ->getContent ();
219
-
220
- case 'metadata ' :
221
- return $ this ->getMetadata ();
222
-
223
- case 'provider ' :
224
- return $ this ->getProvider ();
225
-
226
- case 'statuscode ' :
227
- return $ this ->getStatusCode ();
228
-
229
- default :
230
- $ trace = debug_backtrace ();
231
-
232
- trigger_error (
233
- sprintf (
234
- 'Undefined property via __get(): %s in %s on line %s ' ,
235
- $ name ,
236
- $ trace [0 ]['file ' ],
237
- $ trace [0 ]['line ' ]
238
- ),
239
- E_USER_NOTICE
240
- );
241
-
242
- break ;
243
- }
244
- }
245
183
}
0 commit comments