From 8f7e8013abc88a6f15131fec5c4a9983c3d1cefc Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Fri, 17 Dec 2021 13:37:22 +0100 Subject: [PATCH] Bugfix: Crash when no env initialized --- src/SparkApplication.php | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/SparkApplication.php b/src/SparkApplication.php index 03ecdcd..d6ca5b9 100644 --- a/src/SparkApplication.php +++ b/src/SparkApplication.php @@ -15,7 +15,7 @@ class SparkApplication extends Application { public static SparkApplication $instance; - private Environment $environment; + private ?Environment $environment; private ResourceManager $resourceManager; @@ -32,20 +32,23 @@ class SparkApplication extends Application $this->pluginManager = new PluginManager(); $this->environment = Environment::createFromDirectory(null, true); - $this->environment->loadEnvironment(); + if ($this->environment) { + $this->environment->loadEnvironment(); - $this->add(new Commands\RunCommand()); - $this->add(new Commands\ResourcesCommand()); - $this->add(new Commands\ReplCommand()); - $this->add(new Commands\InitCommand()); - $this->add(new Commands\PipeCommand()); + $this->add(new Commands\RunCommand()); + $this->add(new Commands\ResourcesCommand()); + $this->add(new Commands\ReplCommand()); + $this->add(new Commands\PipeCommand()); - $this->get("list")->setHidden(true); - $this->get("completion")->setHidden(true); - $this->get("help")->setHidden(true); + $this->get("list")->setHidden(true); + $this->get("completion")->setHidden(true); + $this->get("help")->setHidden(true); - if (getenv("SPARK_PLUGINS")) { - $this->add(new Commands\PluginsCommand()); + if (getenv("SPARK_PLUGINS")) { + $this->add(new Commands\PluginsCommand()); + } + } else { + $this->add(new Commands\InitCommand()); } }