-
Notifications
You must be signed in to change notification settings - Fork 1
/
LegacyFramework.php
35 lines (26 loc) · 1.01 KB
/
LegacyFramework.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
namespace App\Middleware;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Slim\Psr7\Factory\ResponseFactory;
final class LegacyFramework implements MiddlewareInterface
{
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$responseFactory = new ResponseFactory();
ob_start();
require_once __DIR__ . '/../../public/legacy-framework.php';
$headers = headers_list();
header_remove();
$response = $responseFactory->createResponse(http_response_code());
$response->getBody()->write(ob_get_clean());
foreach ($headers as $header) {
$pieces = explode(':', $header);
$headerName = array_shift($pieces);
$response = $response->withAddedHeader($headerName, trim(implode(':', $pieces)));
}
return $response;
}
}