Skip to content

Commit 99a40c5

Browse files
Remove create methods
1 parent 5f60799 commit 99a40c5

File tree

4 files changed

+59
-41
lines changed

4 files changed

+59
-41
lines changed

src/Config.php

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,33 @@
1515
*/
1616
class Config implements ConfigInterface
1717
{
18+
/**
19+
* Listeners accept requests
20+
*
21+
* @var array
22+
*/
1823
private array $_listeners;
1924

25+
/**
26+
* Route entities defines internal request routing.
27+
*
28+
* @var array
29+
*/
2030
private array $_routes = [];
2131

32+
/**
33+
* Each app that Unit runs is defined as an object
34+
*
35+
* @var array
36+
*/
2237
private array $_applications = [];
2338

39+
/**
40+
* An upstream is a group of servers that comprise a single logical entity and
41+
* may be used as a pass destination for incoming requests in a listener or a route.
42+
*
43+
* @var array|mixed
44+
*/
2445
private array $_upstreams;
2546

2647
/**
@@ -83,17 +104,6 @@ public function getListeners(): array
83104
return $this->_listeners ?? [];
84105
}
85106

86-
/**
87-
* Create listener
88-
*
89-
* @param $data
90-
* @return void
91-
*/
92-
public function createListener($data)
93-
{
94-
// TODO: Implement createListener() method.
95-
}
96-
97107
/**
98108
* Update listener
99109
*
@@ -126,11 +136,6 @@ public function getApplication($applicationName): ApplicationAbstract
126136
return $this->_applications[$applicationName];
127137
}
128138

129-
public function createApplication($data)
130-
{
131-
// TODO: Implement createApplication() method.
132-
}
133-
134139
/**
135140
* Get routes from config
136141
*
@@ -152,11 +157,6 @@ public function getRoute($routeName)
152157
return $this->_routes[$routeName];
153158
}
154159

155-
public function createRoute($data)
156-
{
157-
// TODO: Implement createRoute() method.
158-
}
159-
160160
/**
161161
* Get upstreams
162162
*
@@ -174,11 +174,14 @@ public function getUpstreams(): mixed
174174
*/
175175
public function toArray(): array
176176
{
177-
return [
178-
'listeners' => $this->_listeners,
179-
'routes' => $this->_routes,
180-
'applications' => $this->_applications,
181-
'upstreams' => $this->_upstreams,
182-
];
177+
$array = [];
178+
179+
foreach (array_keys(get_object_vars($this)) as $key) {
180+
if (!empty($this->{$key})) {
181+
$array[substr($key, 1)] = $this->{$key};
182+
}
183+
}
184+
185+
return $array;
183186
}
184187
}

src/Config/Route.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ class Route
1515

1616
public function __construct(
1717
private readonly string $_name,
18-
$data)
18+
$data)
1919
{
20-
// TODO: implement match and action in block
2120
foreach ($data as $routeBlock) {
2221
$this->_routeBlocks[] = new RouteBlock($routeBlock);
2322
}
@@ -26,7 +25,7 @@ public function __construct(
2625
/**
2726
* Return Listener
2827
*
29-
* @param mixed $listener
28+
* @param mixed $listener
3029
*/
3130
public function setListener(Listener $listener): void
3231
{

src/Config/Routes/RouteAction.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,9 @@ class RouteAction
5050

5151
private string $_chroot;
5252

53-
// TODO: implement getter and setter
54-
private bool $_follow_symlinks;
53+
protected bool $_follow_symlinks;
5554

56-
// TODO: implement getter and setter
57-
private bool $_traverse_mounts;
55+
protected bool $_traverse_mounts;
5856

5957
private string $_rewrite;
6058

@@ -239,6 +237,22 @@ public function setFallback(array $fallback): void
239237
$this->_fallback = $fallback;
240238
}
241239

240+
/**
241+
* @param bool $follow_symlinks
242+
*/
243+
public function setFollowSymlinks(bool $follow_symlinks): void
244+
{
245+
$this->_follow_symlinks = $follow_symlinks;
246+
}
247+
248+
/**
249+
* @param bool $traverse_mounts
250+
*/
251+
public function setTraverseMounts(bool $traverse_mounts): void
252+
{
253+
$this->_traverse_mounts = $traverse_mounts;
254+
}
255+
242256
public function parseFromArray(array $data)
243257
{
244258
if (array_key_exists('pass', $data)) {
@@ -280,5 +294,13 @@ public function parseFromArray(array $data)
280294
if (array_key_exists('fallback', $data)) {
281295
$this->setFallback($data['fallback']);
282296
}
297+
298+
if (array_key_exists('follow_symlinks', $data)) {
299+
$this->setFollowSymlinks($data['follow_symlinks']);
300+
}
301+
302+
if (array_key_exists('traverse_mounts', $data)) {
303+
$this->setTraverseMounts($data['traverse_mounts']);
304+
}
283305
}
284306
}

src/Interfaces/ConfigInterface.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,20 @@
77

88
interface ConfigInterface
99
{
10-
public function getListeners();
10+
public function getListeners(): array;
1111

1212
public function getListenerByPort(int $port): Listener|null;
1313

14-
public function createListener($data);
15-
1614
public function updateListener($data);
1715

1816
public function getRoutes(): array;
1917

2018
public function getRoute($routeName);
2119

22-
public function createRoute($data);
23-
2420
public function getApplications(): array;
2521

2622
public function getApplication($applicationName): ApplicationAbstract;
2723

28-
public function createApplication($data);
29-
3024
public function getUpstreams();
3125

3226
public function toArray(): array;

0 commit comments

Comments
 (0)