diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f06b41..e677549 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 This update introduces minor improvements +### Changed + - Changed properties to become typed properties + +### Added + - Added a new constructor parameter called `path` which is an optional parameter that allows you to specify the path to + the configuration files directory. If not specified the library will proceed with resolving + the path to the configuration files directory using the default method. This will override + the `CONFIGLIB_PATH` environment variable if it is set. + ## [1.1.5] - 2024-12-27 diff --git a/src/ConfigLib/Configuration.php b/src/ConfigLib/Configuration.php index 0a3a20a..77005d8 100644 --- a/src/ConfigLib/Configuration.php +++ b/src/ConfigLib/Configuration.php @@ -1,7 +1,5 @@ path = null; + if($env !== false) { if(file_exists($env)) @@ -64,6 +60,21 @@ } } + if($path !== null) + { + if(!is_dir(dirname($path))) + { + throw new RuntimeException(sprintf('Directory "%s" does not exist', dirname($path))); + } + + if(!is_writable(dirname($path))) + { + throw new RuntimeException(sprintf('Directory "%s" is not writable', dirname($path))); + } + + $this->path = $path; + } + if ($this->path === null) { $filePath = $name . '.conf';