namespace Cli\Commands;
+use Cli\Services\EnvironmentLoader;
use Cli\Services\ProgramRunner;
use Minicli\Command\CommandCall;
use RecursiveDirectoryIterator;
*/
protected function createDatabaseDump(): string
{
+ $envOptions = EnvironmentLoader::loadMergedWithCurrentEnv($this->appDir);
$dbOptions = [
- 'host' => ($_SERVER['DB_HOST'] ?? ''),
- 'username' => ($_SERVER['DB_USERNAME'] ?? ''),
- 'password' => ($_SERVER['DB_PASSWORD'] ?? ''),
- 'database' => ($_SERVER['DB_DATABASE'] ?? ''),
+ 'host' => ($envOptions['DB_HOST'] ?? ''),
+ 'username' => ($envOptions['DB_USERNAME'] ?? ''),
+ 'password' => ($envOptions['DB_PASSWORD'] ?? ''),
+ 'database' => ($envOptions['DB_DATABASE'] ?? ''),
];
- $port = $_SERVER['DB_PORT'] ?? '';
+ $port = $envOptions['DB_PORT'] ?? '';
if ($port) {
$dbOptions['host'] .= ':' . $port;
}
namespace Cli\Commands;
+use Cli\Services\EnvironmentLoader;
use Cli\Services\ProgramRunner;
use Minicli\Command\CommandCall;
$this->ensureRequiredExtensionInstalled(); // TODO - Ensure bookstack install deps are met?
// TODO - Check composer and git exists before running
- // TODO - Look at better way of handling env usage, on demand maybe where needed?
- // Env loading in main `run` script if confilicting with certain bits here (app key generate, hence APP_KEY overload)
- // See dotenv's Dotenv::createArrayBacked as way to go this.
- // (More of a change for 'backup' command).
// TODO - Potentially download composer?
$suggestedOutPath = $input->subcommand;
$errors = (new ProgramRunner('php', '/usr/bin/php'))
->withTimeout(60)
->withIdleTimeout(5)
- ->withEnvironment(['APP_KEY' => 'SomeRandomString'])
+ ->withEnvironment(EnvironmentLoader::load($installDir))
->runCapturingAllOutput([
$installDir . DIRECTORY_SEPARATOR . 'artisan',
'key:generate', '--force', '-n', '-q'
--- /dev/null
+<?php
+
+namespace Cli\Services;
+
+use Dotenv\Dotenv;
+
+class EnvironmentLoader
+{
+ public static function load(string $rootPath): array
+ {
+ $dotenv = Dotenv::createArrayBacked($rootPath);
+ return $dotenv->safeLoad();
+ }
+
+ public static function loadMergedWithCurrentEnv(string $rootPath): array
+ {
+ $env = static::load($rootPath);
+ foreach ($_SERVER as $key => $val) {
+ $env[$key] = $val;
+ }
+ return $env;
+ }
+}
}
$bsDir = dirname($scriptDir);
-// Load in our .env file from the parent directory
-$dotenv = Dotenv\Dotenv::createImmutable($bsDir);
-$dotenv->safeLoad();
-
// Setup our CLI
$app = new App();
$app->setSignature('./run');