Open
Description
Description
I was taking a look at prepared commands and found it confusing as to why the placeholders were required to be passed as environment variables and not separately. Is there a specific reason why they must be intermingled?
This feels a bit risky for two reasons:
- The value of an existing environment variable could be used accidentally if a placeholder value is forgotten and no error would be shown.
- An environment variable could accidentally be overwritten by a placeholder value with the same name and affect the process being called.
Example
I expected it to be something like the following, where the placeholder bindings could be passed as a separate argument and then the environment variables would be left unchanged and it would prevent any collision between environment variable names and placeholder names.
$process = new Process('mysqldump --user="${:db_user}" --password="${:db_pass}" "${:db_name}" > "${:db_backup_path}"');
$process->run(bindings: [
'db_user' => getenv('DB_USER'),
'db_password' => getenv('DB_PASS'),
'db_name' => 'symfony',
'db_backup_path' => '/var/backup/db-'.time().'.sql',
]);
The signature for the run
method would look like this:
public function run(?callable $callback = null, array $env = [], array $bindings = []): int {}