Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattCast44 committed Aug 5, 2022
1 parent ec4baa6 commit 1700585
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

### 0.3.0

- Renamed methods
- Added support for `.env` files

### 0.2.1

- Fix array_filter filtering out all env variables
Expand Down
10 changes: 5 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ You also have the option of calling named methods to set the configuration optio
use Statix\Server\Server;

Server::new()
->usePHP('path')
->onHost('localhost')
->onPort('8080')
->php('path')
->host('localhost')
->port('8080')
->root('./content')
->useRouter('./router.php')
->router('./router.php')
->withEnvVars([
'APP_DYNAMIC_ENV' => 'server'
])->withoutEnvVars([
'APP_KEY',
]);
])->withEnvFile('path/to/.env');
```

### Capturing the output from the server process
Expand Down
16 changes: 13 additions & 3 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Statix\Server;

use Dotenv\Dotenv;
use Exception;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;
Expand Down Expand Up @@ -69,7 +70,7 @@ public function __construct(array $configuration = [])
'withoutEnvVars' => [],
], $configuration);

$this->envVarsToPass = array_merge($_ENV, getenv());
$this->envVarsToPass = array_merge($_ENV, getenv(), $_SERVER);

return $this;
}
Expand All @@ -96,7 +97,7 @@ private function findExecutable(): string

public function getConfiguration(string $key = null): mixed
{
if($key != null) {
if ($key != null) {
return $this->configuration[$key] ?? null;
}

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

public function withEnvFile(string $path): self
{
// todo
if (! file_exists($path)) {
throw new Exception('Given path to env file does not exists: '.$path);
}

(Dotenv::createImmutable(
dirname($path),
basename($path)
))->safeLoad();

$this->envVarsToPass = array_merge($_ENV, getenv(), $_SERVER);

return $this;
}
Expand Down
2 changes: 0 additions & 2 deletions tests/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,3 @@

expect($server->getProcess())->toBeInstanceOf(Process::class);
});

// with env file support
2 changes: 2 additions & 0 deletions tests/resources/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
APP_NAME="Server"
APP_ENV="local"

0 comments on commit 1700585

Please sign in to comment.