Skip to content

Commit

Permalink
fix bug: get x-version from custom process
Browse files Browse the repository at this point in the history
  • Loading branch information
hhxsv5 committed Jul 20, 2020
1 parent 55a072f commit f0c0275
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/Components/Apollo/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ public static function getDefinition()
public static function callback(Server $swoole, SwooleProcess $process)
{
$filename = base_path('.env');
$env = getenv('LARAVELS_ENV');
if ($env !== false) {
$filename .= '.' . $env;
if (isset($_ENV['LARAVEL_ENV'])) {
$filename .= '.' . $_ENV['LARAVEL_ENV'];
}

self::$apollo = Client::createFromEnv();
Expand Down
7 changes: 5 additions & 2 deletions src/Console/Portal.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,11 @@ public function start()

// Generate configuration storage/laravels.json
$options = $this->input->getOptions();
if (isset($options['env'])) {
putenv('LARAVELS_ENV=' . $options['env']);
if (isset($options['env']) && $options['env'] !== '') {
$_SERVER['LARAVEL_ENV'] = $_ENV['LARAVEL_ENV'] = $options['env'];
}
if (isset($options['x-version']) && $options['x-version'] !== '') {
$_SERVER['X_VERSION'] = $_ENV['X_VERSION'] = $options['x-version'];
}

// Load Apollo configurations to .env file
Expand Down
6 changes: 2 additions & 4 deletions src/Illuminate/Laravel.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ public function __construct(array $conf = [])
$this->conf = $conf;

// Merge $_ENV $_SERVER
$server = isset($this->conf['_SERVER']) ? $this->conf['_SERVER'] : [];
$env = isset($this->conf['_ENV']) ? $this->conf['_ENV'] : [];
$this->rawGlobals['_SERVER'] = $_SERVER + $server;
$this->rawGlobals['_ENV'] = $_ENV + $env;
$this->rawGlobals['_SERVER'] = $_SERVER + $this->conf['_SERVER'];
$this->rawGlobals['_ENV'] = $_ENV + $this->conf['_ENV'];
}

public function prepareLaravel()
Expand Down
4 changes: 1 addition & 3 deletions src/LaravelS.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ public function onWorkerError(HttpServer $server, $workerId, $workerPId, $exitCo
protected function convertRequest(Laravel $laravel, SwooleRequest $request)
{
$rawGlobals = $laravel->getRawGlobals();
$server = isset($rawGlobals['_SERVER']) ? $rawGlobals['_SERVER'] : [];
$env = isset($rawGlobals['_ENV']) ? $rawGlobals['_ENV'] : [];
return (new Request($request))->toIlluminateRequest($server, $env);
return (new Request($request))->toIlluminateRequest($rawGlobals['_SERVER'], $rawGlobals['_ENV']);
}

public function onRequest(SwooleRequest $swooleRequest, SwooleResponse $swooleResponse)
Expand Down

0 comments on commit f0c0275

Please sign in to comment.