1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Linna Psr7. |
5
|
|
|
* |
6
|
|
|
* @author Sebastian Rapetti <[email protected]> |
7
|
|
|
* @copyright (c) 2018, Sebastian Rapetti |
8
|
|
|
* @license http://opensource.org/licenses/MIT MIT License |
9
|
|
|
*/ |
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Linna\Http\Message; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Uri trait. |
16
|
|
|
* Provide help methods for Uri class. |
17
|
|
|
*/ |
18
|
|
|
trait UriTrait |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Create uri string. |
22
|
|
|
* |
23
|
|
|
* @param string $scheme |
24
|
|
|
* @param string $authority |
25
|
|
|
* @param string $path |
26
|
|
|
* @param string $query |
27
|
|
|
* @param string $fragment |
28
|
|
|
* |
29
|
|
|
* @return string |
30
|
|
|
*/ |
31
|
19 |
|
private function createUriString( |
32
|
|
|
string $scheme, |
33
|
|
|
string $authority, |
34
|
|
|
string $path, |
35
|
|
|
string $query, |
36
|
|
|
string $fragment |
37
|
|
|
): string { |
38
|
19 |
|
$uri = $scheme.$authority; |
39
|
|
|
|
40
|
19 |
|
$path = ('/' !== substr($path, 0, 1) && $uri !== '' && $path !== '') ? '/'.$path : $path; |
41
|
|
|
|
42
|
19 |
|
return implode('', [$uri, $path, $query, $fragment]); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Get non standard port. |
47
|
|
|
* |
48
|
|
|
* @param int $port |
49
|
|
|
* @param string $scheme |
50
|
|
|
* @param bool $standardScheme |
51
|
|
|
* @param array $supportedSchemes |
52
|
|
|
* |
53
|
|
|
* @return int |
54
|
|
|
*/ |
55
|
7 |
|
private function getNonStandardPort( |
56
|
|
|
int $port, |
57
|
|
|
string $scheme, |
58
|
|
|
bool $standardScheme, |
59
|
|
|
array $supportedSchemes |
60
|
|
|
): int { |
61
|
7 |
|
return (!$port && $standardScheme) ? $supportedSchemes[$scheme] : $port; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get port for standard scheme. |
66
|
|
|
* |
67
|
|
|
* @param bool $standardPort |
68
|
|
|
* @param int $port |
69
|
|
|
* |
70
|
|
|
* @return int |
71
|
|
|
*/ |
72
|
1 |
|
private function getPortForStandardScheme(bool $standardPort, int $port): int |
73
|
|
|
{ |
74
|
1 |
|
return ($standardPort) ? 0 : $port; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Check standard port for current scheme. |
79
|
|
|
* |
80
|
|
|
* @param string $scheme |
81
|
|
|
* @param int $port |
82
|
|
|
* @param array $supportedSchemes |
83
|
|
|
* |
84
|
|
|
* @return bool |
85
|
|
|
*/ |
86
|
8 |
|
private function checkStandardPortForCurretScheme(string $scheme, int $port, array $supportedSchemes): bool |
87
|
|
|
{ |
88
|
8 |
|
return (isset($supportedSchemes[$scheme]) && $port === $supportedSchemes[$scheme]) ? true : false; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|