add data from work folder
This commit is contained in:
parent
528ba365b4
commit
7052803761
218 changed files with 16123 additions and 1233 deletions
38
implementation/13-refactoring/src/Http/BasicEmitter.php
Normal file
38
implementation/13-refactoring/src/Http/BasicEmitter.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Lubian\NoFramework\Http;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
use function header;
|
||||
use function sprintf;
|
||||
use function strtolower;
|
||||
|
||||
final class BasicEmitter implements Emitter
|
||||
{
|
||||
public function emit(ResponseInterface $response, bool $withoutBody = false): void
|
||||
{
|
||||
foreach ($response->getHeaders() as $name => $values) {
|
||||
$first = strtolower($name) !== 'set-cookie';
|
||||
foreach ($values as $value) {
|
||||
$header = sprintf('%s: %s', $name, $value);
|
||||
header($header, $first);
|
||||
$first = false;
|
||||
}
|
||||
}
|
||||
|
||||
$statusLine = sprintf(
|
||||
'HTTP/%s %s %s',
|
||||
$response->getProtocolVersion(),
|
||||
$response->getStatusCode(),
|
||||
$response->getReasonPhrase()
|
||||
);
|
||||
header($statusLine, true, $response->getStatusCode());
|
||||
|
||||
if ($withoutBody) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo $response->getBody();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue