Skip to content

Commit 1700585

Browse files
committed
wip
1 parent ec4baa6 commit 1700585

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
### 0.3.0
4+
5+
- Renamed methods
6+
- Added support for `.env` files
7+
38
### 0.2.1
49

510
- Fix array_filter filtering out all env variables

readme.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@ You also have the option of calling named methods to set the configuration optio
8080
use Statix\Server\Server;
8181

8282
Server::new()
83-
->usePHP('path')
84-
->onHost('localhost')
85-
->onPort('8080')
83+
->php('path')
84+
->host('localhost')
85+
->port('8080')
8686
->root('./content')
87-
->useRouter('./router.php')
87+
->router('./router.php')
8888
->withEnvVars([
8989
'APP_DYNAMIC_ENV' => 'server'
9090
])->withoutEnvVars([
9191
'APP_KEY',
92-
]);
92+
])->withEnvFile('path/to/.env');
9393
```
9494

9595
### Capturing the output from the server process

src/Server.php

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

33
namespace Statix\Server;
44

5+
use Dotenv\Dotenv;
56
use Exception;
67
use Symfony\Component\Process\PhpExecutableFinder;
78
use Symfony\Component\Process\Process;
@@ -69,7 +70,7 @@ public function __construct(array $configuration = [])
6970
'withoutEnvVars' => [],
7071
], $configuration);
7172

72-
$this->envVarsToPass = array_merge($_ENV, getenv());
73+
$this->envVarsToPass = array_merge($_ENV, getenv(), $_SERVER);
7374

7475
return $this;
7576
}
@@ -96,7 +97,7 @@ private function findExecutable(): string
9697

9798
public function getConfiguration(string $key = null): mixed
9899
{
99-
if($key != null) {
100+
if ($key != null) {
100101
return $this->configuration[$key] ?? null;
101102
}
102103

@@ -169,7 +170,16 @@ public function router(string $path): self
169170

170171
public function withEnvFile(string $path): self
171172
{
172-
// todo
173+
if (! file_exists($path)) {
174+
throw new Exception('Given path to env file does not exists: '.$path);
175+
}
176+
177+
(Dotenv::createImmutable(
178+
dirname($path),
179+
basename($path)
180+
))->safeLoad();
181+
182+
$this->envVarsToPass = array_merge($_ENV, getenv(), $_SERVER);
173183

174184
return $this;
175185
}

tests/ServerTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,3 @@
139139

140140
expect($server->getProcess())->toBeInstanceOf(Process::class);
141141
});
142-
143-
// with env file support

tests/resources/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
APP_NAME="Server"
2+
APP_ENV="local"

0 commit comments

Comments
 (0)