Skip to content

Commit 95c3250

Browse files
update file
1 parent 25fec2c commit 95c3250

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ function esc(string $text): string
639639
*/
640640
function csrf(): string
641641
{
642-
return '<input type="hidden" name="_token" value="' . app()->getCsrfToken() . '">';
642+
return '<input type="hidden" name="csrfToken" value="' . app()->getCsrfToken() . '">';
643643
}
644644

645645
}

src/libraries/Http/Response.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ public function make(?string $content = '', array $headers = [], int $status = 2
122122
*/
123123
public function send(): void
124124
{
125-
126125
if (func_num_args() > 0) {
127126
$this->make(...func_get_args());
128127
}
@@ -277,6 +276,30 @@ public function download(string $filePath, string $fileName = null, array $addit
277276
return $this;
278277
}
279278

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+
280303
/**
281304
* Output content encoded as a JSON string.
282305
*/
@@ -300,7 +323,7 @@ public function toArray(string $content): array
300323
/**
301324
* Returns response in XML format
302325
**/
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
304327
{
305328
$xmlContent = $this->convertToXml($data);
306329
if ($xmlContent !== null) {
@@ -313,7 +336,7 @@ public function toXml(mixed $data, int $statusCode = 200, string $charset = 'utf
313336
/**
314337
* Converts data to XML format
315338
**/
316-
private function convertToXml($data): ?string
339+
private function convertToXml(array|object $data): ?string
317340
{
318341
$xml = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><root></root>');
319342
array_walk_recursive($data, [$xml, 'addChild']);

0 commit comments

Comments
 (0)