File tree Expand file tree Collapse file tree 5 files changed +25
-10
lines changed
Expand file tree Collapse file tree 5 files changed +25
-10
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change @@ -80,16 +80,16 @@ You also have the option of calling named methods to set the configuration optio
8080use Statix\Server\Server;
8181
8282Server::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
Original file line number Diff line number Diff line change 22
33namespace Statix \Server ;
44
5+ use Dotenv \Dotenv ;
56use Exception ;
67use Symfony \Component \Process \PhpExecutableFinder ;
78use 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 }
Original file line number Diff line number Diff line change 139139
140140 expect ($ server ->getProcess ())->toBeInstanceOf (Process::class);
141141});
142-
143- // with env file support
Original file line number Diff line number Diff line change 1+ APP_NAME = " Server"
2+ APP_ENV = " local"
You can’t perform that action at this time.
0 commit comments