Skip to content

[Process] Prepared command placeholders #57337

Open
@willrowe

Description

@willrowe

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:

  1. The value of an existing environment variable could be used accidentally if a placeholder value is forgotten and no error would be shown.
  2. 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 {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy