From 936485dde74f2c7b74903663bb2687fd16ad0f66 Mon Sep 17 00:00:00 2001 From: netkas Date: Tue, 7 Jan 2025 21:14:03 -0500 Subject: [PATCH] - 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. - Changed properties to become typed properties --- CHANGELOG.md | 9 ++++++++ src/ConfigLib/Configuration.php | 39 +++++++++++++++++++++------------ 2 files changed, 34 insertions(+), 14 deletions(-) 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';