diff --git a/dev/bootstrap-controller.php b/dev/bootstrap-controller.php index 8bfd347..1e0b169 100644 --- a/dev/bootstrap-controller.php +++ b/dev/bootstrap-controller.php @@ -16,7 +16,11 @@ exit(1); } -$upwardConfig = getenv('UPWARD_PHP_UPWARD_PATH'); +// populate the $_SERVER superglobal with environment variables if we're running with PHP's built-in server +if (PHP_SAPI === 'cli-server') { + $_SERVER = array_merge(getenv(), $_SERVER); +} +$upwardConfig = $_SERVER['UPWARD_PHP_UPWARD_PATH'] ?? null; if (!$upwardConfig) { echo 'No path to UPWARD YAML file provided.' . PHP_EOL; exit(1); diff --git a/src/Context.php b/src/Context.php index a22286a..ae56696 100644 --- a/src/Context.php +++ b/src/Context.php @@ -64,7 +64,7 @@ public static function fromRequest(Request $request): self 'query' => $request->getQuery()->toArray(), ], ], - 'env' => getenv(), + 'env' => $_SERVER, ]); } diff --git a/test/ContextTest.php b/test/ContextTest.php index 68ac6d2..091e6a1 100644 --- a/test/ContextTest.php +++ b/test/ContextTest.php @@ -68,8 +68,8 @@ public function testFromRequest(): void $request->shouldReceive('getUri->getQuery') ->andReturn('query=query-value'); - putenv('ENV_NAME=envValue'); - $subject = Context::fromRequest($request); + $_SERVER['ENV_NAME'] = 'envValue'; + $subject = Context::fromRequest($request); verify($subject->get('request.headers.Request-Header'))->is()->sameAs('header value'); verify($subject->get('request.headerEntries.0.key'))->is()->sameAs('Request-Header');