22
33namespace Pavlusha311245 \UnitPhpSdk \Config \Routes ;
44
5+ use Pavlusha311245 \UnitPhpSdk \Exceptions \UnitException ;
6+
57class RouteAction
68{
9+ /**
10+ * Destination for the request, identical to a listener’s pass option.
11+ *
12+ * @var string
13+ */
714 private string $ _pass ;
15+
16+ /**
17+ * Socket address of an HTTP server to where the request is proxied.
18+ *
19+ * @var string
20+ */
821 private string $ _proxy ;
22+
23+ /**
24+ * HTTP status code with a context-dependent redirect location.
25+ * Integer (000–999); defines the HTTP response status code to be returned.
26+ *
27+ * @var int
28+ */
929 private int $ _return ;
30+
31+ /**
32+ * String URI; used if the return value implies redirection.
33+ *
34+ * @var string
35+ */
1036 private string $ _location ;
37+
38+ /**
39+ * Lists file paths that are tried until a file is found.
40+ *
41+ * @var array|string
42+ */
1143 private array |string $ _share ;
44+
45+ private string $ _index ;
46+
47+ private array $ _fallback ;
48+
49+ private array $ _types ;
50+
51+ private string $ _chroot ;
52+
53+ // TODO: implement getter and setter
54+ private bool $ _follow_symlinks ;
55+
56+ // TODO: implement getter and setter
57+ private bool $ _traverse_mounts ;
58+
1259 private string $ _rewrite ;
1360
14- public function __construct ($ data )
61+ public function __construct ($ data = null )
1562 {
16- $ this ->_share = $ data ['share ' ] ?? null ;
63+ if (!empty ($ data )) {
64+ $ this ->parseFromArray ($ data );
65+ }
66+
67+ // $this->_share = $data['share'] ?? null;
1768 }
1869
1970 /**
@@ -26,6 +77,14 @@ public function getReturn()
2677 return $ this ->_return ;
2778 }
2879
80+ /**
81+ * @return string
82+ */
83+ public function getPass (): string
84+ {
85+ return $ this ->_pass ;
86+ }
87+
2988 /**
3089 * Set return key
3190 *
@@ -39,4 +98,187 @@ public function setReturn(int $return): void
3998
4099 $ this ->_return = $ return ;
41100 }
101+
102+ /**
103+ * @param string $pass
104+ */
105+ public function setPass (string $ pass ): void
106+ {
107+ $ this ->_pass = $ pass ;
108+ }
109+
110+ /**
111+ * @return string
112+ */
113+ public function getProxy (): string
114+ {
115+ return $ this ->_proxy ;
116+ }
117+
118+ /**
119+ * @param string $proxy
120+ */
121+ public function setProxy (string $ proxy ): void
122+ {
123+ $ this ->_proxy = $ proxy ;
124+ }
125+
126+ /**
127+ * @return string
128+ */
129+ public function getLocation (): string
130+ {
131+ return $ this ->_location ;
132+ }
133+
134+ /**
135+ * @param string $location
136+ */
137+ public function setLocation (string $ location ): void
138+ {
139+ $ this ->_location = $ location ;
140+ }
141+
142+ /**
143+ * @return string
144+ */
145+ public function getRewrite (): string
146+ {
147+ return $ this ->_rewrite ;
148+ }
149+
150+ /**
151+ * @param string $rewrite
152+ */
153+ public function setRewrite (string $ rewrite ): void
154+ {
155+ $ this ->_rewrite = $ rewrite ;
156+ }
157+
158+ /**
159+ * @return array|string
160+ */
161+ public function getShare (): array |string
162+ {
163+ return $ this ->_share ;
164+ }
165+
166+ /**
167+ * @param array|string $share
168+ */
169+ public function setShare (array |string $ share ): void
170+ {
171+ $ this ->_share = $ share ;
172+ }
173+
174+ /**
175+ * @return string
176+ */
177+ public function getIndex (): string
178+ {
179+ return $ this ->_index ;
180+ }
181+
182+ /**
183+ * @param string $index
184+ */
185+ public function setIndex (string $ index ): void
186+ {
187+ $ this ->_index = $ index ;
188+ }
189+
190+ /**
191+ * @return string
192+ */
193+ public function getChroot (): string
194+ {
195+ return $ this ->_chroot ;
196+ }
197+
198+ /**
199+ * @param string $chroot
200+ */
201+ public function setChroot (string $ chroot ): void
202+ {
203+ $ this ->_chroot = $ chroot ;
204+ }
205+
206+ /**
207+ * @return array
208+ */
209+ public function getTypes (): array
210+ {
211+ return $ this ->_types ;
212+ }
213+
214+ /**
215+ * @param array $types
216+ */
217+ public function setTypes (array $ types ): void
218+ {
219+ $ this ->_types = $ types ;
220+ }
221+
222+ /**
223+ * @return array
224+ */
225+ public function getFallback (): array
226+ {
227+ return $ this ->_fallback ;
228+ }
229+
230+ /**
231+ * @param array $fallback
232+ */
233+ public function setFallback (array $ fallback ): void
234+ {
235+ if (!array_key_exists ('pass ' , $ fallback ) && !array_key_exists ('proxy ' , $ fallback )) {
236+ throw new UnitException ('Parse Exception ' );
237+ }
238+
239+ $ this ->_fallback = $ fallback ;
240+ }
241+
242+ public function parseFromArray (array $ data )
243+ {
244+ if (array_key_exists ('pass ' , $ data )) {
245+ $ this ->setPass ($ data ['pass ' ]);
246+ }
247+
248+ if (array_key_exists ('proxy ' , $ data )) {
249+ $ this ->setProxy ($ data ['proxy ' ]);
250+ }
251+
252+ if (array_key_exists ('return ' , $ data )) {
253+ $ this ->setReturn ($ data ['return ' ]);
254+ }
255+
256+ if (array_key_exists ('location ' , $ data )) {
257+ $ this ->setLocation ($ data ['location ' ]);
258+ }
259+
260+ if (array_key_exists ('rewrite ' , $ data )) {
261+ $ this ->setRewrite ($ data ['rewrite ' ]);
262+ }
263+
264+ if (array_key_exists ('share ' , $ data )) {
265+ $ this ->setShare ($ data ['share ' ]);
266+ }
267+
268+ if (array_key_exists ('index ' , $ data )) {
269+ $ this ->setIndex ($ data ['index ' ]);
270+ }
271+
272+ if (array_key_exists ('chroot ' , $ data )) {
273+ $ this ->setChroot ($ data ['chroot ' ]);
274+ }
275+
276+ if (array_key_exists ('types ' , $ data )) {
277+ $ this ->setTypes ($ data ['types ' ]);
278+ }
279+
280+ if (array_key_exists ('fallback ' , $ data )) {
281+ $ this ->setFallback ($ data ['fallback ' ]);
282+ }
283+ }
42284}
0 commit comments