php-shell-wrapper icon indicating copy to clipboard operation
php-shell-wrapper copied to clipboard

Add support for environment variables

Open smalot opened this issue 8 years ago • 2 comments

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 avatar Mar 19 '16 14:03 smalot

@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...

adambrett avatar Mar 21 '16 12:03 adambrett

Sounds good !

smalot avatar Mar 21 '16 13:03 smalot