Once a .php script within
site-root begins handling a request, it can output whatever headers and content it wants.
Most responses will be rendered by the RequestHandler::respond method though. The static property
RequestHandler::$responseMode determines what format a response will be
rendered in, and defaults to
'html'. Scripts or extending classes may switch $responseMode to based on their own logic.
RequestHandler::respond is invoked, it takes two parameters:
$responseData. Regardless of response mode,
$responseId will always be provided
to the client via the
X-Response-ID response header.
This is the simplest response mode,
$responseData is encoded to JSON and outputted with
The default response mode, a dwoo template will be searched for in
html-templates combining the
$responseId with the request path from right-to-left. Output from the
template will be returned to the client with
To continue the example from the routing page, if the request handler at
RequestHandler::respond('projectEdit', ['success' => true, 'data' => $Project]), the site would search in this order to find the best template:
In the code for codeforphilly.org, #3 will match first and be used to render the responseData to HTML, with each key in the responseData array becoming a variable available from dwoo.
Handled the same way as html, but template output will be returned to the client with
'return' mode, an array containing
data will be returned from the respond() fuction to the caller.
A template is found following the same logic as for the
'html' response mode, but responseId is suffixed with
Content-Type: application/pdf. For the example request described above, a template named
projectEdit.pdf.tpl would need to be found.
CSV::fromRecords method is used to attempt to render
$responseData in CSV format with
Content-Type: text/csv and
Content-Disposition: attachment; filename=$responseId.csv
Emergence Development Roadmap
- There should be a way for classes extending RequestHandler to declare a list of allowed response modes which will be automatically selected from based on the