Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Inject the list of env vars that are passed on to the web server #38211

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/Illuminate/Foundation/Console/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ class ServeCommand extends Command
*/
protected $portOffset = 0;

/**
* The environment variables that are passed thru to the built-in PHP webserver.
*
* @var array
*/
protected $passthruEnvVars;

/**
* Create a new serve command instance.
*
* @param array $passthruEnvVars
* @return void
*/
public function __construct(array $passthruEnvVars = ['APP_ENV', 'LARAVEL_SAIL', 'PHP_CLI_SERVER_WORKERS'])
{
parent::__construct();

$this->passthruEnvVars = $passthruEnvVars;
}
Comment on lines +47 to +52
Copy link
Contributor

@scott-davidjones scott-davidjones Aug 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this allow the user to remove the required APP_ENV and LARAVEL_SAIL environment variables? Originally those two were hard coded, presumably as they are required.

This will allow the user to effectively remove those variables by not passing them into the allowed array. Perhaps have a default array and array_merge the incoming $passthruEnvVars.

for example:

$this->passthruEnvVars = \array_merge(['APP_ENV', 'LARAVEL_SAIL', 'PHP_CLI_SERVER_WORKERS'], $passthruEnvVars);


/**
* Execute the console command.
*
Expand Down Expand Up @@ -100,7 +120,7 @@ protected function startProcess($hasEnvironment)
return [$key => $value];
}

return in_array($key, ['APP_ENV', 'LARAVEL_SAIL', 'PHP_CLI_SERVER_WORKERS'])
return in_array($key, $this->passthruEnvVars)
? [$key => $value]
: [$key => false];
})->all());
Expand Down