/** * @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); } } }
/** * Dotenv constructor. * @param string $filePath */ public function __construct($filePath) { parent::__construct($filePath); if (file_exists($filePath)) { $this->load(); } }
public function clearEnvironmentVariable($name) { parent::cleanEnvironmentVariable($name); if (!$this->immutable) { unset($this->notenv_data[$name]); } }
/** * Assert that the callback returns true for each variable. * * @param callable $callback * @param string $message * * @return \Dotenv\Validator */ protected function assertCallback($callback, $message = 'failed callback assertion') { if (!is_callable($callback)) { throw new \InvalidArgumentException('Callback must be callable'); } $variablesFailingAssertion = array(); foreach ($this->variables as $variableName) { $variableValue = $this->loader->getEnvironmentVariable($variableName); if (call_user_func($callback, $variableValue) === false) { $variablesFailingAssertion[] = $variableName . " {$message}"; } } if (count($variablesFailingAssertion) > 0) { throw new \RuntimeException(sprintf('One or more environment variables failed assertions: %s', implode(', ', $variablesFailingAssertion))); } return $this; }
/** * @override * @inheritDoc */ public function clearEnvironmentVariable($name) { if (strpos($name, 'INI_') === 0) { $normalized = str_replace('INI_', '', $name); $normalized = strtolower($normalized); $this->invoker->call('ini_restore', [$normalized]); } parent::clearEnvironmentVariable($name); }
/** * Load `.env` file in given directory. * * @return array */ public function overload() { $this->loader = new Loader($this->filePath, $immutable = false); return $this->loader->load(); }
/** * Actually load the data. * * @param bool $overload * * @return array */ protected function loadData($overload = false) { $this->loader = new Loader($this->filePath, !$overload); return $this->loader->load(); }