22
33namespace Pavlusha311245 \UnitPhpSdk \Config ;
44
5+ use Pavlusha311245 \UnitPhpSdk \Exceptions \UnitException ;
6+
57class Listener
68{
7- private $ _link ;
9+ private string $ _link ;
810 private array $ _pass = [];
9- private string $ _listener ;
10- private $ _port ;
11+ private int $ _port ;
1112
1213 public function __construct (
13- string $ listener ,
14- string $ pass = '' ,
15- private array $ _tls = [],
16- private array $ _forwarded = [],
14+ private string $ _listener ,
15+ string $ pass = '' ,
16+ private array $ _tls = [],
17+ private array $ _forwarded = [],
1718 )
1819 {
19- $ this ->_listener = $ listener ;
20- $ this ->_port = explode (': ' , $ listener )[1 ];
20+ $ this ->parsePort ();
21+ $ this ->generateLink ();
22+
2123 if (!empty ($ pass )) {
2224 $ this ->_pass = explode ('/ ' , $ pass );
2325 }
2426 }
2527
28+ /**
29+ * Get link
30+ *
31+ * @return string
32+ */
33+ public function getLink (): string
34+ {
35+ return $ this ->_link ;
36+ }
37+
38+ /**
39+ * Generate link from listener
40+ *
41+ * @return void
42+ */
43+ private function generateLink ()
44+ {
45+ $ separatedListener = explode (': ' , $ this ->_listener );
46+
47+ $ this ->_link = $ separatedListener [0 ] == '* ' ?
48+ "0.0.0.0: {$ separatedListener [1 ]}" : $ separatedListener ;
49+ }
50+
51+ /**
52+ * Parse port
53+ *
54+ * @return void
55+ */
56+ private function parsePort (): void
57+ {
58+ $ this ->_port = explode (': ' , $ this ->_listener )[1 ];
59+ }
60+
61+ /**
62+ * Get port
63+ *
64+ * @return int
65+ */
66+ public function getPort (): int
67+ {
68+ return $ this ->_port ;
69+ }
70+
71+ /**
72+ * Get forwarded
73+ *
74+ * @return array
75+ */
2676 public function getForwarded (): array
2777 {
2878 return $ this ->_forwarded ;
2979 }
3080
81+ /**
82+ * Get pass
83+ *
84+ * @return array
85+ */
3186 public function getPass (): array
3287 {
3388 return $ this ->_pass ;
3489 }
3590
91+ /**
92+ * Get tls section
93+ *
94+ * @return array
95+ */
3696 public function getTls (): array
3797 {
3898 return $ this ->_tls ;
3999 }
40100
41101 /**
102+ * Get listener
103+ *
42104 * @return mixed
43105 */
44106 public function getListener ()
@@ -49,12 +111,12 @@ public function getListener()
49111 /**
50112 * Parse data from array
51113 *
52- * @throws \Exception
114+ * @throws UnitException
53115 */
54116 public function parseFromArray (array $ data ): Listener
55117 {
56118 if (!array_key_exists ('pass ' , $ data )) {
57- throw new \ Exception ("Missing required 'pass' array key " );
119+ throw new UnitException ("Missing required 'pass' array key " );
58120 }
59121
60122 $ this ->_pass = explode ('/ ' , $ data ['pass ' ]);
0 commit comments