Skip to content

Commit b9c9ff7

Browse files
committed
Adding optional request path the request data object
1 parent 8115ccd commit b9c9ff7

File tree

5 files changed

+29
-21
lines changed

5 files changed

+29
-21
lines changed

src/DataObjects/Data.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
final class Data
88
{
99
/**
10-
* @param Server $server The Server Object.
11-
* @param Language $language The Language Object.
12-
* @param Request $request The Request Object.
13-
* @param Response $response The Response Object.
14-
* @param list<Error> $errors The list of Errors.
10+
* @param Server $server The Server Object.
11+
* @param Language $language The Language Object.
12+
* @param Request $request The Request Object.
13+
* @param Response $response The Response Object.
14+
* @param list<Error> $errors The list of Errors.
1515
*/
1616
public function __construct(
1717
public Server $server,

src/DataObjects/Request.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@
99
final class Request
1010
{
1111
/**
12-
* @param string $timestamp The timestamp of the request in the format: YYYY-MM-DD hh:mm:ss.
13-
* @param string $ip The real IP address of the request.
14-
* @param string $url The full URL of the request including query data if any.
15-
* @param string $user_agent The User Agent of the request.
16-
* @param null|Method $method The HTTP method of the request, uppercase if possible.
17-
* @param array<int|string,string> $headers The request headers for the request in key:value format.
18-
* @param array<int|string,mixed> $body The complete request data sent with this request.
19-
* @param array<int|string,mixed> $raw The raw body from the request.
12+
* @param string $timestamp The timestamp of the request in the format: YYYY-MM-DD hh:mm:ss.
13+
* @param string $ip The real IP address of the request.
14+
* @param string $url The full URL of the request including query data if any.
15+
* @param null|string $route_path The path of the route from the framework.
16+
* @param string $user_agent The User Agent of the request.
17+
* @param null|Method $method The HTTP method of the request, uppercase if possible.
18+
* @param array<int|string,string> $headers The request headers for the request in key:value format.
19+
* @param array<int|string,mixed> $body The complete request data sent with this request.
20+
* @param array<int|string,mixed> $raw The raw body from the request.
2021
*/
2122
public function __construct(
2223
public string $timestamp,
2324
public string $ip,
2425
public string $url,
26+
public null|string $route_path,
2527
public string $user_agent,
2628
public null|Method $method,
2729
public array $headers,
@@ -35,6 +37,7 @@ public function __construct(
3537
* timestamp: string,
3638
* ip: string,
3739
* url: string,
40+
* route_path: null|string,
3841
* user_agent: string,
3942
* method: string|null,
4043
* headers: array,
@@ -48,6 +51,7 @@ public function __toArray(): array
4851
'timestamp' => $this->timestamp,
4952
'ip' => $this->ip,
5053
'url' => $this->url,
54+
'route_path' => $this->route_path,
5155
'user_agent' => $this->user_agent,
5256
'method' => $this->method->value ?? null,
5357
'headers' => $this->headers,

tests/DataObjects/DataTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
declare(strict_types=1);
44

5-
65
use Treblle\Utils\Http\Method;
76

87
it('can cast an object to an array', function (string $string): void {
@@ -42,12 +41,13 @@
4241
'name' => $string,
4342
'version' => $string,
4443
'expose_php' => $string,
45-
'display_errors' => $string
44+
'display_errors' => $string,
4645
],
4746
'request' => [
4847
'timestamp' => $string,
4948
'ip' => $string,
5049
'url' => $string,
50+
'route_path' => $string,
5151
'user_agent' => $string,
5252
'method' => Method::GET->value,
5353
'headers' => [
@@ -69,7 +69,7 @@
6969
'load_time' => 12.3,
7070
'body' => [
7171
$string => $string,
72-
]
72+
],
7373
],
7474
'errors' => [
7575
[
@@ -78,7 +78,7 @@
7878
'message' => $string,
7979
'file' => $string,
8080
'line' => 123,
81-
]
82-
]
81+
],
82+
],
8383
]);
8484
})->with('strings');

tests/DataObjects/RequestTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
timestamp: $string,
1111
ip: $string,
1212
url: $string,
13+
route_path: $string,
1314
user_agent: $string,
1415
method: Method::DELETE,
1516
headers: [
@@ -35,6 +36,7 @@
3536
timestamp: $string,
3637
ip: $string,
3738
url: $string,
39+
route_path: $string,
3840
user_agent: $string,
3941
method: Method::GET,
4042
headers: [
@@ -44,7 +46,7 @@
4446
$string => $string,
4547
],
4648
raw: [
47-
$string => $string
49+
$string => $string,
4850
]
4951
);
5052

@@ -54,6 +56,7 @@
5456
'timestamp' => $string,
5557
'ip' => $string,
5658
'url' => $string,
59+
'route_path' => $string,
5760
'user_agent' => $string,
5861
'method' => Method::GET->value,
5962
'headers' => [
@@ -63,7 +66,7 @@
6366
$string => $string,
6467
],
6568
'raw' => [
66-
$string => $string
67-
]
69+
$string => $string,
70+
],
6871
]);
6972
})->with('strings');

tests/Pest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function createData(string $string): Data
4141
timestamp: $string,
4242
ip: $string,
4343
url: $string,
44+
route_path: $string,
4445
user_agent: $string,
4546
method: Method::GET,
4647
headers: [

0 commit comments

Comments
 (0)