From 0d8844f499746980b0ff7fbdd0ffa051bf92f17a Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Wed, 8 Dec 2021 22:19:20 +0100 Subject: [PATCH] Updated readme, misc fixes * Look for spark config in parent directories * Version tracking via src/version --- .gitignore | 4 +++- README.md | 6 +++++- bin/spark | 6 ++++++ src/Environment/Environment.php | 15 ++++++++++++++- src/SparkApplication.php | 4 ++-- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 741dfee..fd372cd 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ /.phpunit.cache /*.phar /.spark -/.spark.json \ No newline at end of file +/.spark.json +/src/version +/release diff --git a/README.md b/README.md index 629b94d..5b5236a 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,8 @@ The advantage of writing your extensions as plugins: - Object-oriented interface - Delayed evaluation of code, ensuring dependencies are loaded +- Free autoloader! The namespace and path of the plugin class will be used to + set up a Psr-4 autoloader for your code. ### Scripts @@ -64,9 +66,11 @@ Using scripts is the simplest way to leverage Spark: `.php`-files are executed in-process, and as such have access to any registered resources, resource types and plugins. +*Note: The script system need to be improved and revamped to support environment variables and such* + ### Resources Resources are wrappers around database connections and such, providing a cleaner interface to its innards. - +Resources are generally registered by plugins. diff --git a/bin/spark b/bin/spark index 240495c..15fa8d8 100755 --- a/bin/spark +++ b/bin/spark @@ -1,6 +1,12 @@ #!/usr/bin/env php getPluginManager()->initializePlugins(); } - public static function createFromDirectory(string|null $directory=null): Environment + public static function createFromDirectory(string|null $directory=null, bool $parents=false): Environment { $directory = $directory ?? getcwd(); + + if ($parents) { + $check = $directory; + while (!glob("{$check}/.spark*")) { + $p = dirname($check); + if ($p == $check) break; + $check = $p; + } + if (strlen($directory) > 1) { + $directory = $check; + } + } + $candidates = [ $directory . "/.spark.json", $directory . "/.spark/spark.json" ]; $config = []; while ($candidate = array_shift($candidates)) { diff --git a/src/SparkApplication.php b/src/SparkApplication.php index d2542d6..2bea94c 100644 --- a/src/SparkApplication.php +++ b/src/SparkApplication.php @@ -25,13 +25,13 @@ class SparkApplication extends Application public function __construct() { - parent::__construct("Spark", "dev"); + parent::__construct("Spark", APP_VERSION); self::$instance = $this; $this->resourceManager = new ResourceManager(); $this->pluginManager = new PluginManager(); - $this->environment = Environment::createFromDirectory(); + $this->environment = Environment::createFromDirectory(null, true); $this->environment->loadEnvironment(); $this->add(new Commands\RunCommand());