mirror of
https://github.com/andres-montanez/Magallanes
synced 2024-06-16 12:35:04 +02:00
Obtain environment variables
This commit is contained in:
parent
f4c3817b37
commit
6b207eb480
|
@ -307,4 +307,53 @@ abstract class AbstractTask
|
|||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the array of environment variables
|
||||
* Returned array contains both system variables and variables set in config
|
||||
* WARNING: To access system's variables you need to set proper value in your php.ini at variables_order key
|
||||
* @see http://php.net/manual/en/ini.core.php#ini.variables-order
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getEnvVariables()
|
||||
{
|
||||
$configVars = array_merge(
|
||||
$this->getConfig()->general('env', []),
|
||||
$this->getConfig()->environmentConfig('env', []),
|
||||
$this->getConfig()->getParameter('env', [])
|
||||
);
|
||||
|
||||
if (isset($configVars['variables'])) {
|
||||
$configVars = $configVars['variables'];
|
||||
}
|
||||
|
||||
$envVariables = array_merge(
|
||||
$_ENV,
|
||||
$configVars
|
||||
);
|
||||
|
||||
return $envVariables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns ready to inject environment string
|
||||
* The string is build from env vars array in schema:
|
||||
* key1=value1 key2=value3 ...
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getEnvVarsString()
|
||||
{
|
||||
$envVarsArray = $this->getEnvVariables();
|
||||
$envVars = array_map(
|
||||
function ($key, $value) {
|
||||
return "$key=$value";
|
||||
},
|
||||
array_keys($envVarsArray),
|
||||
$this->getEnvVariables()
|
||||
);
|
||||
|
||||
return join(' ', $envVars);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue