Skip to content

Commit 7c2a564

Browse files
committed
Implemented methods getAcceptLanguage(), getReferrer(), and getRequestTime().
1 parent 789ab98 commit 7c2a564

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"license": "MIT",
1010
"require": {
1111
"php": ">=7.3",
12-
"plaisio/request": "^0.10.0"
12+
"plaisio/request": "^0.10.2"
1313
},
1414
"require-dev": {
1515
"phing/phing": "^2.0",

src/CoreRequest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@
1616
*/
1717
class CoreRequest implements Request
1818
{
19+
//--------------------------------------------------------------------------------------------------------------------
20+
/**
21+
* Returns the accepted languages by the user agent.
22+
*
23+
* @return string|null
24+
*
25+
* @api
26+
* @since 1.0.0
27+
*/
28+
public function getAcceptLanguage(): ?string
29+
{
30+
return $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? null;
31+
}
32+
1933
//--------------------------------------------------------------------------------------------------------------------
2034
/**
2135
* Returns the method of the current request.
@@ -40,6 +54,21 @@ public function getMethod(): string
4054
return 'GET';
4155
}
4256

57+
//--------------------------------------------------------------------------------------------------------------------
58+
/**
59+
* Returns the URL of the page (if any) which referred the user agent to the current page. This is set by the user
60+
* agent and cannot be trusted.
61+
*
62+
* @return string|null
63+
*
64+
* @api
65+
* @since 1.0.0
66+
*/
67+
public function getReferrer(): ?string
68+
{
69+
return $_SERVER['HTTP_REFERER'] ?? null;
70+
}
71+
4372
//--------------------------------------------------------------------------------------------------------------------
4473
/**
4574
* Returns the remote IP (this is always the next hop, not necessarily the user's IP address).
@@ -54,6 +83,20 @@ public function getRemoteIp(): ?string
5483
return $_SERVER['REMOTE_ADDR'] ?? null;
5584
}
5685

86+
//--------------------------------------------------------------------------------------------------------------------
87+
/**
88+
* Returns the timestamp of the start of the request, with microsecond precision.
89+
*
90+
* @return float|null
91+
*
92+
* @api
93+
* @since 1.0.0
94+
*/
95+
public function getRequestTime(): ?float
96+
{
97+
return $_SERVER['REQUEST_TIME_FLOAT'] ?? null;
98+
}
99+
57100
//--------------------------------------------------------------------------------------------------------------------
58101
/**
59102
* Returns the requested relative URL after. It includes the query part if any.

0 commit comments

Comments
 (0)