Skip to content

Commit c506a57

Browse files
authored
add custom responses (fix #21) (#22)
* add custom echo response resolves #21 * add js response
1 parent 9a02b3c commit c506a57

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/Response.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ public function httpVersion(?string $version = null)
5454
return $this;
5555
}
5656

57+
/**
58+
* Output any text
59+
*
60+
* @param string $data The data to output
61+
* @param int $code The response status code
62+
*/
63+
public function echo(string $data, int $code = 200)
64+
{
65+
$this->status = $code;
66+
$this->headers['Content-Type'] ??= 'text/plain';
67+
$this->content = $data;
68+
69+
$this->send();
70+
}
71+
5772
/**
5873
* Output plain text
5974
*
@@ -83,6 +98,21 @@ public function xml(string $data, int $code = 200)
8398

8499
$this->send();
85100
}
101+
102+
/**
103+
* Output js script
104+
*
105+
* @param string $data The data to output
106+
* @param int $code The response status code
107+
*/
108+
public function js(string $data, int $code = 200)
109+
{
110+
$this->status = $code;
111+
$this->headers['Content-Type'] = 'text/javascript';
112+
$this->content = $data;
113+
114+
$this->send();
115+
}
86116

87117
/**
88118
* Output json encoded data with an HTTP code/message

0 commit comments

Comments
 (0)