You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Web/Sources/src/app/router/request/RequestFactory.php

27 lines
898 B

<?php
namespace App\Router\Request;
class RequestFactory {
public static function createFromGlobals(): IRequest {
$query = $_GET;
$server = $_SERVER;
$headers = self::getRequestHeaders();
$contentType = $headers['Content-Type'] ?? '';
$contentStrategy = ContentStrategyFactory::createContentStrategy($contentType, $server['REQUEST_METHOD']);
return new HttpRequest($query, $server, $headers, $contentStrategy,[]);
}
// should not be heare
private static function getRequestHeaders(): array {
$headers = [];
foreach ($_SERVER as $key => $value) {
if (substr($key, 0, 5) === 'HTTP_') {
$header = str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))));
$headers[$header] = $value;
}
}
return $headers;
}
}