php-shell-wrapper
php-shell-wrapper copied to clipboard
Add support for environment variables
Hi,
In webserver context, environment variable are often skipped or wrong, because forced by the webserver process itself. So it's necessary to prefix any executed command line by a set of environment variable assignments.
eg: the environment variable 'HOME' is missing when php is run under Apache.
A function like addEnvironmentVariable('HOME', '/home/username')
could prefix any command line with:
$> HOME="/home/username" ....
So, could you add this support ?
Many thanks
@smalot I'm looking in to this, I don't really want to add a method for environment variables, at the moment I'm thinking of either a scoped command, or a scoped runner, something like this:
$env = new Environment(new Exec(), $workingDir, $env);
$env->run($command);
or maybe
$env = new Environment($workingDir, ['home' => '/home/abc/']);
$shell = new Exec($env);
$shell->run($command);
or on the command instead:
$command = new Command(...);
$envCommand = new Environment($command, $workingDir, $env);
$shell->run($envCommand);
or...
$command = new Command(...);
$shell = new Exec();
$env = new Environment($workingDir, $envVars);
$shell->run($command, $env);
Just ideas at the moment, not sure what direction to take it in...
Sounds good !