-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRequestHttpParams.php
More file actions
72 lines (59 loc) · 1.52 KB
/
RequestHttpParams.php
File metadata and controls
72 lines (59 loc) · 1.52 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/*
* This file is part of the Tiny package.
*
* (c) Alex Ermashev <alexermashev@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Tiny\Http;
class RequestHttpParams implements RequestSystemParamsInterface
{
const BASE_SCRIPT_NAME = '/index.php';
/**
* @var array
*/
private array $server;
/**
* RequestHttpParams constructor.
*
* @param array $server
*/
public function __construct(array $server)
{
$this->server = $server;
}
/**
* @return string
*/
public function getMethod(): string
{
return $this->server['REQUEST_METHOD'] ?? '';
}
/**
* @return string
*/
public function getRequest(): string
{
$uri = $this->server['REQUEST_URI'] ?? '';
// remove all trailing slashes
$requestedUri = rtrim(parse_url($uri, PHP_URL_PATH), '/');
// remove the base script name from the requested uri (we may work from a sub dir)
$subDirectory = str_replace(
self::BASE_SCRIPT_NAME,
'',
($this->server['SCRIPT_NAME'] ?? '')
);
$request = strtolower(str_replace($subDirectory, '', $requestedUri));
// at least a one single slash should be returned
return $request ?: '/';
}
/**
* @return mixed
*/
public function getRawRequest()
{
return file_get_contents('php://input');
}
}