@@ -122,7 +122,6 @@ public function make(?string $content = '', array $headers = [], int $status = 2
122
122
*/
123
123
public function send (): void
124
124
{
125
-
126
125
if (func_num_args () > 0 ) {
127
126
$ this ->make (...func_get_args ());
128
127
}
@@ -277,6 +276,30 @@ public function download(string $filePath, string $fileName = null, array $addit
277
276
return $ this ;
278
277
}
279
278
279
+ /**
280
+ * Output content encoded as a Html string.
281
+ */
282
+ public function toHtml (?string $ content , int $ statusCode = 200 , string $ charset = 'utf-8 ' ): void
283
+ {
284
+ if (!is_string ($ content )) {
285
+ throw new RuntimeException ('Content must be a string to be converted to HTML. ' );
286
+ }
287
+
288
+ $ this ->send ($ content , [], $ statusCode , 'text/html; charset= ' . $ charset );
289
+ }
290
+
291
+ /**
292
+ * Output content encoded as a Text string.
293
+ */
294
+ public function toText ($ content , int $ statusCode = 200 , string $ charset = 'utf-8 ' ): void
295
+ {
296
+ if (!is_string ($ content )) {
297
+ throw new RuntimeException ('Content must be a string to be converted to Text. ' );
298
+ }
299
+
300
+ $ this ->send ($ content , [], $ statusCode , 'application/text ' , $ charset );
301
+ }
302
+
280
303
/**
281
304
* Output content encoded as a JSON string.
282
305
*/
@@ -300,7 +323,7 @@ public function toArray(string $content): array
300
323
/**
301
324
* Returns response in XML format
302
325
**/
303
- public function toXml (mixed $ data , int $ statusCode = 200 , string $ charset = 'utf-8 ' ): void
326
+ public function toXml (array | object $ data , int $ statusCode = 200 , string $ charset = 'utf-8 ' ): void
304
327
{
305
328
$ xmlContent = $ this ->convertToXml ($ data );
306
329
if ($ xmlContent !== null ) {
@@ -313,7 +336,7 @@ public function toXml(mixed $data, int $statusCode = 200, string $charset = 'utf
313
336
/**
314
337
* Converts data to XML format
315
338
**/
316
- private function convertToXml ($ data ): ?string
339
+ private function convertToXml (array | object $ data ): ?string
317
340
{
318
341
$ xml = new \SimpleXMLElement ('<?xml version="1.0" encoding="UTF-8"?><root></root> ' );
319
342
array_walk_recursive ($ data , [$ xml , 'addChild ' ]);
0 commit comments