Service CleanProcess hinzugefügt: Umgebung für Docker- und Symfony-Variablen bereinigt
This commit is contained in:
46
src/Service/Process/CleanProcess.php
Normal file
46
src/Service/Process/CleanProcess.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* CleanProcess.php 2026-03-27 thomas
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Thomas Schneider <thomas@inter-mundos.de>
|
||||||
|
* Alle Rechte vorbehalten.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Service\Process;
|
||||||
|
|
||||||
|
use Symfony\Component\Process\Process;
|
||||||
|
|
||||||
|
class CleanProcess extends Process
|
||||||
|
{
|
||||||
|
public function start(?callable $callback = null, array $env = []): void
|
||||||
|
{
|
||||||
|
// von docker compose gesetzte Umgebungsvariablen zurücksetzen
|
||||||
|
$this->parseEnvVars('DOCKER_DOTENV_VARS', $env);
|
||||||
|
|
||||||
|
// Symfony dotenv-Variablen für den Prozess zurücksetzen
|
||||||
|
$this->parseEnvVars('SYMFONY_DOTENV_VARS', $env);
|
||||||
|
|
||||||
|
parent::start($callback, $env);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function parseEnvVars(string $keySelector, array &$env): void
|
||||||
|
{
|
||||||
|
$preservedKeys = [];
|
||||||
|
|
||||||
|
if(empty(getenv($keySelector)))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// prepare DDEV-Environments
|
||||||
|
if(getenv('IS_DDEV_PROJECT'))
|
||||||
|
{
|
||||||
|
$preservedKeys += ['SSH_AUTH_SOCK'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$vars = array_fill_keys(explode(',', getenv($keySelector)), false);
|
||||||
|
|
||||||
|
$env = [...array_diff_key($vars, array_flip($preservedKeys)), ...$env];
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user