Skip to content

Instantly share code, notes, and snippets.

@jm42
Created October 18, 2014 02:29
Show Gist options
  • Save jm42/c0ab0ca6c5c0912ffed4 to your computer and use it in GitHub Desktop.
Save jm42/c0ab0ca6c5c0912ffed4 to your computer and use it in GitHub Desktop.
Response send
<?php
function send(Response $response) {
if (headers_sent()) {
return;
}
http_response_code($response->status);
foreach ($response->headers as $key => $value) {
if (is_array($value)) {
foreach ($value as $content) {
header($key . ': ' . $content, false);
}
continue;
}
header($key . ': ' . $value);
}
if ($response->body !== null) {
file_put_contents('php://output', $response->body);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment