1 | <?php |
||
8 | class Port implements UriPartInterface |
||
9 | { |
||
10 | protected $port = null; |
||
11 | |||
12 | /** |
||
13 | * Port constructor. Accepts an integer or null value representing a URI port component. Construction will throw an |
||
14 | * exception if port is not an integer or is not null or if the given integer is outside of the allowed TCP/UDP |
||
15 | * range of 1 to 65535. |
||
16 | * |
||
17 | * port = *DIGIT |
||
18 | * |
||
19 | * @see https://tools.ietf.org/html/rfc3986#appendix-A |
||
20 | * |
||
21 | * @throws \InvalidArgumentException if the given port is not an integer or null or if the given integer is out of |
||
22 | * range |
||
23 | * |
||
24 | * @param int|null $port A string representing a URI port |
||
25 | */ |
||
26 | 11 | public function __construct($port) |
|
36 | |||
37 | /** |
||
38 | * Returns a string representation of the port. |
||
39 | * |
||
40 | * @return string The string representation of the port |
||
41 | */ |
||
42 | 3 | public function __toString() |
|
46 | |||
47 | /** |
||
48 | * Validates a given port. A port is valid if it is either null or an integer between 1 and 65535 inclusive. |
||
49 | * |
||
50 | * @param mixed $port The port to be validated |
||
51 | * @return bool Returns true if the given port is valid |
||
52 | * Returns false otherwise |
||
53 | */ |
||
54 | 10 | public static function isValid($port) |
|
66 | |||
67 | /** |
||
68 | * Returns a string representation of the port formatted so that it can be compiled into a complete URI string |
||
69 | * per the Uri object's string specification. |
||
70 | * |
||
71 | * If the port is empty, toUriString returns an empty string; if the port is not empty, toUriString returns the |
||
72 | * port prefixed with a colon. |
||
73 | * |
||
74 | * @see Uri::__toString |
||
75 | * |
||
76 | * @return string A string representation of the port formatted for a complete URI string |
||
77 | */ |
||
78 | 2 | public function toUriString() |
|
88 | |||
89 | /** |
||
90 | * Validates whether a given port falls within the range of valid ports for TCP/UDP (1 to 65535) |
||
91 | * |
||
92 | * @param int $port The port to be validated |
||
93 | * |
||
94 | * @return bool Returns true if the port falls within the valid range |
||
95 | * Returns false otherwise |
||
96 | */ |
||
97 | 7 | private static function portIsInValidRange($port) |
|
105 | } |
||
106 |