setEnvironmentVariable() public method

This is done using: - putenv, - $_ENV, - $_SERVER. The environment variable value is stripped of single and double quotes.
public setEnvironmentVariable ( string $name, string | null $value = null ) : void
$name string
$value string | null
return void
Esempio n. 1
0
 /**
  * @override
  * @inheritDoc
  */
 public function setEnvironmentVariable($name, $value = null)
 {
     if (strpos($name, 'INI_') === 0) {
         list($name, $value) = $this->normaliseEnvironmentVariable($name, $value);
         $normalized = str_replace('INI_', '', $name);
         $normalized = strtolower($normalized);
         $this->invoker->call('ini_set', [$normalized, $value]);
     }
     parent::setEnvironmentVariable($name, $value);
 }
Esempio n. 2
0
 /**
  * @inheritDoc
  */
 public function boot()
 {
     $filePath = rtrim($this->kernel->getRootPath(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '.env';
     $envLoader = new Loader($filePath);
     if ($this->kernel->isCli()) {
         /** @var InputInterface $consoleInput */
         $consoleInput = $this->container->get(InputInterface::class);
         $env = $consoleInput->getParameterOption(['--env', '-e']);
         if ($env) {
             $envLoader->setEnvironmentVariable('APP_ENV', $env);
         }
     }
 }