Skip to content

Commit

Permalink
update file
Browse files Browse the repository at this point in the history
  • Loading branch information
juancristobalgd1 authored Jun 9, 2024
1 parent 25fec2c commit 95c3250
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ function esc(string $text): string
*/
function csrf(): string
{
return '<input type="hidden" name="_token" value="' . app()->getCsrfToken() . '">';
return '<input type="hidden" name="csrfToken" value="' . app()->getCsrfToken() . '">';
}

}
29 changes: 26 additions & 3 deletions src/libraries/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ public function make(?string $content = '', array $headers = [], int $status = 2
*/
public function send(): void
{

if (func_num_args() > 0) {
$this->make(...func_get_args());
}
Expand Down Expand Up @@ -277,6 +276,30 @@ public function download(string $filePath, string $fileName = null, array $addit
return $this;
}

/**
* Output content encoded as a Html string.
*/
public function toHtml(?string $content, int $statusCode = 200, string $charset = 'utf-8'): void
{
if (!is_string($content)) {
throw new RuntimeException('Content must be a string to be converted to HTML.');
}

$this->send($content, [], $statusCode, 'text/html; charset=' . $charset);
}

/**
* Output content encoded as a Text string.
*/
public function toText($content, int $statusCode = 200, string $charset = 'utf-8'): void
{
if (!is_string($content)) {
throw new RuntimeException('Content must be a string to be converted to Text.');
}

$this->send($content, [], $statusCode, 'application/text', $charset);
}

/**
* Output content encoded as a JSON string.
*/
Expand All @@ -300,7 +323,7 @@ public function toArray(string $content): array
/**
* Returns response in XML format
**/
public function toXml(mixed $data, int $statusCode = 200, string $charset = 'utf-8'): void
public function toXml(array|object $data, int $statusCode = 200, string $charset = 'utf-8'): void
{
$xmlContent = $this->convertToXml($data);
if ($xmlContent !== null) {
Expand All @@ -313,7 +336,7 @@ public function toXml(mixed $data, int $statusCode = 200, string $charset = 'utf
/**
* Converts data to XML format
**/
private function convertToXml($data): ?string
private function convertToXml(array|object $data): ?string
{
$xml = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><root></root>');
array_walk_recursive($data, [$xml, 'addChild']);
Expand Down

0 comments on commit 95c3250

Please sign in to comment.