Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit 545cf2e

Browse files
Update RouteAction.php.
1 parent 22ab436 commit 545cf2e

File tree

3 files changed

+249
-32
lines changed

3 files changed

+249
-32
lines changed

src/Config.php

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function getApplications(): array
121121
* @param $applicationName
122122
* @return mixed
123123
*/
124-
public function getApplication($applicationName)
124+
public function getApplication($applicationName): ApplicationAbstract
125125
{
126126
return $this->_applications[$applicationName];
127127
}
@@ -167,28 +167,6 @@ public function getUpstreams(): mixed
167167
return $this->_upstreams;
168168
}
169169

170-
/**
171-
* Setup access log file path
172-
*
173-
* @return void
174-
*/
175-
public function setApplicationLogPath($path)
176-
{
177-
// TODO: Implement setApplicationLogPath() method.
178-
// Implement functions from this source https://unit.nginx.org/configuration/#access-log
179-
}
180-
181-
/**
182-
* Setup access log file format
183-
*
184-
* @return void
185-
*/
186-
public function setApplicationLogFormat($format)
187-
{
188-
// TODO: Implement setApplicationLogFormat() method.
189-
// Implement functions from this source https://unit.nginx.org/configuration/#access-log
190-
}
191-
192170
/**
193171
* Return config as array
194172
*

src/Config/Routes/RouteAction.php

Lines changed: 244 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,69 @@
22

33
namespace Pavlusha311245\UnitPhpSdk\Config\Routes;
44

5+
use Pavlusha311245\UnitPhpSdk\Exceptions\UnitException;
6+
57
class 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
}

src/Interfaces/ConfigInterface.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Pavlusha311245\UnitPhpSdk\Interfaces;
44

5+
use Pavlusha311245\UnitPhpSdk\Abstract\ApplicationAbstract;
56
use Pavlusha311245\UnitPhpSdk\Config\Listener;
67

78
interface ConfigInterface
@@ -14,23 +15,19 @@ public function createListener($data);
1415

1516
public function updateListener($data);
1617

17-
public function getRoutes();
18+
public function getRoutes(): array;
1819

1920
public function getRoute($routeName);
2021

2122
public function createRoute($data);
2223

23-
public function getApplications();
24+
public function getApplications(): array;
2425

25-
public function getApplication($applicationName);
26+
public function getApplication($applicationName): ApplicationAbstract;
2627

2728
public function createApplication($data);
2829

2930
public function getUpstreams();
3031

31-
public function setApplicationLogPath($path);
32-
33-
public function setApplicationLogFormat($format);
34-
3532
public function toArray(): array;
3633
}

0 commit comments

Comments
 (0)