Sending
source link: https://sapienphp.com/1.x/response/sending.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
1.2.8. Sending
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
usingheader()
calls; the default version is 1.1 and the default code is 200 -
send each of the
$headers
usingheader()
calls -
send each of the
$cookies
usingsetcookie()
andsetrawcookie()
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).
1.2.8.1. Content Handling
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()
willrewind()
it and send it withfpassthru()
. -
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 forsendContent()
to echo, or do both. -
an iterable, then
sendContent()
willforeach()
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).
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK