public function send() : void
To send the Response, call its send()
method. Doing so will:
call each of the $headerCallbacks
in order
send the status line $version
and $code
using header()
calls; the default version is 1.1 and the default code is 200
send each of the $headers
using header()
calls
send each of the $cookies
using setcookie()
and setrawcookie()
as appropriate
send the content using the Response sendContent()
method (see below for
details).
Note that the send()
method, unlike most Response methods, is not
declared as final. This means you can override it in extended Response classes
(though of course the signature must remain).
protected function sendContent() : void
Recall that the setContent()
method allows anything to be content: a string,
an object, a resource, etc. It is the sendContent()
method that determines
how to actually send the Response content.
If the content is ...
a resource or SplFileObject, then sendContent()
will rewind()
it and
send it with fpassthru()
.
a non-string callable, then sendContent()
will invoke it. Further,
sendContent()
will echo the return value (if any) from that invocation. This
means the callable may emit output itself, or it may return a string for
sendContent()
to echo, or do both.
an iterable, then sendContent()
will foreach()
through it, and echo
each value.
a string or a Stringable, then sendContent()
will merely echo it.
anything else, then sendContent()
will do nothing, and return.
The above conditions are in precedence order. That is, if the content is both callable and iterable, the callable handling will take precedence over the iterable handling.
Note that the sendContent()
method, unlike most Response methods, is not
declared as final. This means you can override it in extended Response classes
(though of course the signature must remain).