-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUri.php
More file actions
37 lines (27 loc) · 936 Bytes
/
Uri.php
File metadata and controls
37 lines (27 loc) · 936 Bytes
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
<?php
declare(strict_types=1);
namespace TinyBlocks\Http\Internal\Request;
use Psr\Http\Message\ServerRequestInterface;
final readonly class Uri
{
private const string ROUTE = '__route__';
private function __construct(private ServerRequestInterface $request, private string $routeAttributeName)
{
}
public static function from(ServerRequestInterface $request): Uri
{
return new Uri(request: $request, routeAttributeName: self::ROUTE);
}
public function route(string $name = self::ROUTE): Uri
{
return new Uri(request: $this->request, routeAttributeName: $name);
}
public function get(string $key): Attribute
{
$attribute = $this->request->getAttribute($this->routeAttributeName);
if (is_array($attribute)) {
return Attribute::from(value: $attribute[$key] ?? null);
}
return Attribute::from(value: $attribute);
}
}