$Response
- is system object, that provides unified target for all needed response data, instance can be obtained in such way:
$Response = \cs\Response::instance();
$Response
object has next public method:
- init()
- init_with_typical_default_settings()
- header()
- redirect()
- cookie()
- output_default()
init($body = '', $body_stream = null, $headers = [], $code = 200, $protocol = 'HTTP/1.1') : \cs\Response
Initialize response object with specified data
Initialize with typical default settings (headers Content-Type
and Vary
, protocol taken from cs\Request::$protocol
)
Set raw HTTP header
Make redirect to specified location
Function for setting cookies, taking into account cookies prefix. Parameters like in system setcookie()
function, but $path
, $domain
and $secure
are skipped, they are detected automatically
Provides default output for all the response data using header()
, http_response_code()
and echo
or php://output
$Response
object has next public properties:
- code
- headers
- body
- body_stream
HTTP status code
Headers are normalized to lowercase keys with hyphen as separator, for instance: connection
, referer
, content-type
, accept-language
String body (is used instead of body_stream
in most cases, ignored if body_stream
is present)
Body in form of stream (might be used instead of body
in some cases, if present, body
is ignored)