Skip to content

Commit e3f497c

Browse files
committed
wip
1 parent c7c58b9 commit e3f497c

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

readme.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ You can configure the several options with the server, such as the host, the por
3434

3535
### Passing configuration via the constructor or Server::new()
3636

37-
You may pass most configuration options via the constructor as shown below where we set the `host`, `port` and `root` options.
37+
You may pass most configuration options via the constructor. For example we are setting the `host`, `port` and `root` options in the code below.
3838

3939
```PHP
40+
use Statix\Server\Server;
41+
4042
Server::new([
4143
'host' => 'localhost',
4244
'port' => 8000,
@@ -50,7 +52,11 @@ new Server([
5052
'port' => 8000,
5153
'root' => __DIR__ . '/content'
5254
]);
55+
```
56+
57+
The complete list of configuration items that can be passed via the constructor can be found below.
5358

59+
```PHP
5460
$optionsSettableViaContructor = [
5561
'host' => 'string', // default: localhost
5662
'port' => 'string|int', // default: 8000
@@ -65,8 +71,10 @@ $optionsSettableViaContructor = [
6571

6672
### Setting configuration via the named methods
6773

74+
You also have the option of calling named methods to set the configuration options as shown below.
75+
6876
```PHP
69-
use Statix\Server;
77+
use Statix\Server\Server;
7078

7179
Server::new()
7280
->usePHP('path')
@@ -75,10 +83,8 @@ Server::new()
7583
->root('./content')
7684
->useRouter('./router.php')
7785
->withoutEnvVars([
78-
//
79-
])->filterEnvVars(function($value, $key) {
80-
//
81-
})
86+
'APP_KEY',
87+
]);
8288
```
8389

8490
### Capturing the output from the server process

src/Server.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@ class Server
1010
{
1111
/**
1212
* The user passed configuration array
13-
*
14-
* @param array $baseConfiguration
13+
*
14+
* @param array $baseConfiguration
1515
*/
1616
protected $baseConfiguration;
1717

1818
/**
1919
* The default and user merged configuration array
20-
*
21-
* @param array $configuration
20+
*
21+
* @param array $configuration
2222
*/
2323
protected $configuration;
2424

2525
/**
2626
* The output handler to pass process output to
27-
*
28-
* @param callable $outputHandler
27+
*
28+
* @param callable $outputHandler
2929
*/
3030
protected $outputHandler;
3131

3232
/**
3333
* The env vars which will be passed to the server process
34-
*
35-
* @param array $envVarsToPass
34+
*
35+
* @param array $envVarsToPass
3636
*/
3737
protected $envVarsToPass;
3838

@@ -46,11 +46,11 @@ public function __construct(array $configuration = [])
4646
$this->baseConfiguration = $configuration;
4747

4848
$this->configuration = array_merge($defaults = [
49-
'host' => 'localhost',
50-
'port' => 8000,
51-
'root' => getcwd(),
49+
'host' => 'localhost',
50+
'port' => 8000,
51+
'root' => getcwd(),
5252
'executable' => null,
53-
'router' => null,
53+
'router' => null,
5454
'withoutEnvVars' => [],
5555
], $configuration);
5656

@@ -116,11 +116,11 @@ public function useRouter(string $path): self
116116
public function filterEnvVars(callable $callback): self
117117
{
118118
$this->envVarsToPass = array_filter(
119-
$this->envVarsToPass,
120-
$callback,
119+
$this->envVarsToPass,
120+
$callback,
121121
ARRAY_FILTER_USE_BOTH
122122
);
123-
123+
124124
return $this;
125125
}
126126

@@ -129,7 +129,7 @@ private function findExecutable(): string
129129
if ($this->configuration['executable'] != null) {
130130
return $this->configuration['executable'];
131131
}
132-
132+
133133
return (new PhpExecutableFinder)->find(false);
134134
}
135135

@@ -147,7 +147,7 @@ private function buildServeCommand(): array
147147

148148
private function buildPassingEnvVarArray(): array
149149
{
150-
return array_filter($this->envVarsToPass, function($key) {
150+
return array_filter($this->envVarsToPass, function ($key) {
151151
return in_array($key, $this->configuration['withoutEnvVars']);
152152
}, ARRAY_FILTER_USE_KEY);
153153
}
@@ -163,7 +163,7 @@ private function initProcess(): Process
163163
);
164164

165165
$process->start(function ($type, $buffer) {
166-
if($this->outputHandler != null) {
166+
if ($this->outputHandler != null) {
167167
($this->outputHandler)($buffer);
168168
}
169169
});
@@ -188,4 +188,4 @@ public function runInBackground(): int|null
188188

189189
return $process->getExitCode();
190190
}
191-
}
191+
}

0 commit comments

Comments
 (0)