diff --git a/libs/Config.php b/libs/Config.php index 05f9f20..d589ddb 100644 --- a/libs/Config.php +++ b/libs/Config.php @@ -129,4 +129,23 @@ class Config extends ArrayObject return $this['html']['inherit_index']; } + + public function setConfigurationOverrideFile($override_file) + { + $this['override_file'] = $override_file; + } + + public function getConfigurationOverrideFile() + { + if (array_key_exists('override_file', $this)) { + return $this['override_file']; + } + + return null; + } + + public function getConfluenceConfiguration() + { + return $this['confluence']; + } } diff --git a/libs/Console/Serve.php b/libs/Console/Serve.php index f9ad7d7..e44c533 100755 --- a/libs/Console/Serve.php +++ b/libs/Console/Serve.php @@ -42,9 +42,9 @@ class Serve extends DauxCommand putenv('DAUX_SOURCE=' . $daux->getParams()->getDocumentationDirectory()); putenv('DAUX_THEME=' . $daux->getParams()->getThemesPath()); + putenv('DAUX_CONFIGURATION=' . $daux->getParams()->getConfigurationOverrideFile()); - //TODO :: support configuration and processor - //putenv('DAUX_CONFIGURATION=' . $daux->getParams()->getConfigurationFile()); + //TODO :: support processor //putenv('DAUX_PROCESSOR=' . $daux->getParams()->getProcessorFile()); $base = ProcessUtils::escapeArgument(__DIR__ . '/../../'); diff --git a/libs/Daux.php b/libs/Daux.php index 273f61f..3421f30 100644 --- a/libs/Daux.php +++ b/libs/Daux.php @@ -68,7 +68,7 @@ class Daux * @param string $override_file * @throws Exception */ - public function initializeConfiguration($override_file = 'config.json') + public function initializeConfiguration($override_file = null) { $params = $this->getParams(); @@ -79,8 +79,10 @@ class Daux $this->loadConfiguration($docs_path . DIRECTORY_SEPARATOR . 'config.json'); // Read command line overrides - if (!is_null($override_file)) { - $this->loadConfiguration($this->local_base . DIRECTORY_SEPARATOR . $override_file); + $override_file = $this->getConfigurationOverride($override_file); + if ($override_file != null) { + $params->setConfigurationOverrideFile($override_file); + $this->loadConfiguration($override_file); } // Validate and set theme path @@ -94,6 +96,30 @@ class Daux } } + public function getConfigurationOverride($override_file) + { + // When running through `daux --serve` we set an environment variable to know where we started from + $env = getenv('DAUX_CONFIGURATION'); + if ($env && file_exists($env)) { + return $env; + } + + if ($override_file == null) { + return null; + } + + if (file_exists($override_file)) { + return getcwd() . '/' . $override_file; + } + + $newPath = $this->local_base . DIRECTORY_SEPARATOR . $override_file; + if (file_exists($newPath)) { + return $newPath; + } + + throw new Exception('The configuration override file does not exist. Check the path again : ' . $override_file); + } + public function normalizeThemePath($path) { // When running through `daux --serve` we set an environment variable to know where we started from diff --git a/libs/Format/Confluence/Generator.php b/libs/Format/Confluence/Generator.php index 8e216a3..ee9bf24 100644 --- a/libs/Format/Confluence/Generator.php +++ b/libs/Format/Confluence/Generator.php @@ -24,6 +24,34 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator public function __construct(Daux $daux) { $this->daux = $daux; + + $this->checkConfiguration(); + } + + public function checkConfiguration() + { + $config = $this->daux->getParams(); + $confluence = $config->getConfluenceConfiguration(); + + if ($confluence == null) { + throw new \RuntimeException("You must specify your Confluence configuration"); + } + + $mandatory = ['space_id', 'base_url', 'user', 'pass', 'prefix']; + $errors = []; + foreach ($mandatory as $key) { + if (!array_key_exists($key, $confluence)) { + $errors[] = $key; + } + } + + if (count($errors)) { + throw new \RuntimeException("The following options are mandatory for confluence : '" . join("', '", $errors) . "'"); + } + + if (!array_key_exists('ancestor_id', $confluence) && !array_key_exists('root_id', $confluence)) { + throw new \RuntimeException("You must specify an 'ancestor_id' or a 'root_id' for confluence."); + } } /**