|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace OpenEngine\Mika\Core\Components\Http\Message\Uri\Traits; |
|
4
|
|
|
|
|
5
|
|
|
trait CloneableHostTrait |
|
6
|
|
|
{ |
|
7
|
|
|
use HostTrait; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Return an instance with the specified scheme. |
|
11
|
|
|
* |
|
12
|
|
|
* This method MUST retain the state of the current instance, and return |
|
13
|
|
|
* an instance that contains the specified scheme. |
|
14
|
|
|
* |
|
15
|
|
|
* Implementations MUST support the schemes "http" and "https" case |
|
16
|
|
|
* insensitively, and MAY accommodate other schemes if required. |
|
17
|
|
|
* |
|
18
|
|
|
* An empty scheme is equivalent to removing the scheme. |
|
19
|
|
|
* |
|
20
|
|
|
* @param string $scheme The scheme to use with the new instance. |
|
21
|
|
|
* @return static A new instance with the specified scheme. |
|
22
|
|
|
* @throws \InvalidArgumentException for invalid or unsupported schemes. |
|
23
|
|
|
*/ |
|
24
|
|
|
public function withScheme($scheme) |
|
25
|
|
|
{ |
|
26
|
|
|
$clone = clone $this; |
|
27
|
|
|
return $clone->setScheme($scheme); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Return an instance with the specified user information. |
|
32
|
|
|
* |
|
33
|
|
|
* This method MUST retain the state of the current instance, and return |
|
34
|
|
|
* an instance that contains the specified user information. |
|
35
|
|
|
* |
|
36
|
|
|
* Password is optional, but the user information MUST include the |
|
37
|
|
|
* user; an empty string for the user is equivalent to removing user |
|
38
|
|
|
* information. |
|
39
|
|
|
* |
|
40
|
|
|
* @param string $user The user name to use for authority. |
|
41
|
|
|
* @param null|string $password The password associated with $user. |
|
42
|
|
|
* @return static A new instance with the specified user information. |
|
43
|
|
|
*/ |
|
44
|
|
|
public function withUserInfo($user, $password = null) |
|
45
|
|
|
{ |
|
46
|
|
|
$clone = clone $this; |
|
47
|
|
|
return $clone->setUser($user)->setPassword($password); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Return an instance with the specified host. |
|
52
|
|
|
* |
|
53
|
|
|
* This method MUST retain the state of the current instance, and return |
|
54
|
|
|
* an instance that contains the specified host. |
|
55
|
|
|
* |
|
56
|
|
|
* An empty host value is equivalent to removing the host. |
|
57
|
|
|
* |
|
58
|
|
|
* @param string $host The hostname to use with the new instance. |
|
59
|
|
|
* @return static A new instance with the specified host. |
|
60
|
|
|
* @throws \InvalidArgumentException for invalid hostnames. |
|
61
|
|
|
*/ |
|
62
|
|
|
public function withHost($host) |
|
63
|
|
|
{ |
|
64
|
|
|
$clone = clone $this; |
|
65
|
|
|
return $clone->setHost($host); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Return an instance with the specified port. |
|
70
|
|
|
* |
|
71
|
|
|
* This method MUST retain the state of the current instance, and return |
|
72
|
|
|
* an instance that contains the specified port. |
|
73
|
|
|
* |
|
74
|
|
|
* Implementations MUST raise an exception for ports outside the |
|
75
|
|
|
* established TCP and UDP port ranges. |
|
76
|
|
|
* |
|
77
|
|
|
* A null value provided for the port is equivalent to removing the port |
|
78
|
|
|
* information. |
|
79
|
|
|
* |
|
80
|
|
|
* @param null|int $port The port to use with the new instance; a null value |
|
81
|
|
|
* removes the port information. |
|
82
|
|
|
* @return static A new instance with the specified port. |
|
83
|
|
|
* @throws \InvalidArgumentException for invalid ports. |
|
84
|
|
|
*/ |
|
85
|
|
|
public function withPort($port) |
|
86
|
|
|
{ |
|
87
|
|
|
$clone = clone $this; |
|
88
|
|
|
return $clone->setPort($port); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|