* workaround in api if PATH_INFO is not set by webserver

This commit is contained in:
maxpozdeev 2022-11-04 16:48:37 +03:00
parent 30b64c355b
commit a91aaa09af

View file

@ -14,7 +14,22 @@ class ApiRequest
public $jsonBody;
function __construct() {
$this->path = $_SERVER['PATH_INFO'] ?? '';
if (isset($_SERVER['PATH_INFO'])) {
$this->path = $_SERVER['PATH_INFO'];
}
else {
$uri = $_SERVER['REQUEST_URI'];
if (false !== $p = strpos($uri, '?')) {
$uri = substr($uri, 0, $p);
}
$script = $_SERVER['SCRIPT_NAME'];
if (0 === $p = strpos($uri, $script)) {
$this->path = substr($uri, strlen($script));
}
else {
$this->path = '';
}
}
$this->method = isset($_SERVER['REQUEST_METHOD']) ? strtoupper($_SERVER['REQUEST_METHOD']) : 'GET';
$this->contentType = $_SERVER['CONTENT_TYPE'] ?? '';
}