1 | <?php |
||
25 | class Port extends AbstractComponent implements PortInterface |
||
26 | { |
||
27 | use ValidatorTrait; |
||
28 | |||
29 | /** |
||
30 | * Validate Port data |
||
31 | * |
||
32 | * @param null|int $port |
||
33 | * |
||
34 | * @throws InvalidArgumentException if the submitted port is invalid |
||
35 | * |
||
36 | * @return null|int |
||
37 | */ |
||
38 | 205 | protected function validate($port) |
|
39 | { |
||
40 | 205 | if ('' === $port) { |
|
41 | 3 | throw new InvalidArgumentException( |
|
42 | 1 | 'Expected port to be a int or null; received an empty string' |
|
43 | 2 | ); |
|
44 | } |
||
45 | |||
46 | 202 | return $this->validatePort($port); |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * Returns the instance string representation |
||
51 | * with its optional URI delimiters |
||
52 | * |
||
53 | * @return string |
||
54 | */ |
||
55 | 158 | public function getUriComponent() |
|
56 | { |
||
57 | 158 | return null === $this->data ? '' : PortInterface::DELIMITER.$this->data; |
|
58 | } |
||
59 | |||
60 | /** |
||
61 | * Return an integer representation of the Port component |
||
62 | * |
||
63 | * @return null|int |
||
64 | */ |
||
65 | 583 | public function toInt() |
|
66 | { |
||
67 | 583 | return $this->data; |
|
68 | } |
||
69 | |||
70 | /** |
||
71 | * Initialize the Port data |
||
72 | * |
||
73 | * @param null|int $data |
||
74 | */ |
||
75 | 205 | protected function init($data) |
|
79 | |||
80 | /** |
||
81 | * @inheritdoc |
||
82 | */ |
||
83 | 2 | public function __debugInfo() |
|
87 | } |
||
88 |