From 386e1375472259be86ae4ad57e2d176f135683fd Mon Sep 17 00:00:00 2001 From: netkas Date: Mon, 23 Sep 2024 13:48:41 -0400 Subject: [PATCH 1/7] Updated CHANGELOG.md --- CHANGELOG.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 530ea12..449338a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,24 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.1.0] - 2024-09-23 + +This update introduces changes for PHP 8.3 & NCC 2.1.0+ compatibility + +### Added + - Added PhpUnit tests for the library + - Added new option `--path` to the CLI interface to display the path to the configuration file + +### Changed + - Updated the codebase to be compatible with PHP 8.3 + - Updated the codebase to be compatible with NCC 2.1.0+ + - Updated Makefile + +### Fixed + - Fixed regex patterns to be more robust + + + ## [1.0.4] - 2023-08-12 This update introduces minor improvements From 0c837c6b5433515bc04ecfb05f191f136be8430f Mon Sep 17 00:00:00 2001 From: netkas Date: Mon, 23 Sep 2024 13:50:21 -0400 Subject: [PATCH 2/7] Add --build-source flag to ncc build commands --- .github/workflows/ci.yml | 2 +- Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e7c392a..29623cd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,7 +51,7 @@ jobs: - name: Build project run: | - ncc build --config release --log-level debug + ncc build --config release --build-source --log-level debug - name: Upload build artifacts uses: actions/upload-artifact@v4 diff --git a/Makefile b/Makefile index c6e2ca2..86f53a1 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ all: build # Build Steps build: - ncc build --config=$(CONFIG) --log-level $(LOG_LEVEL) + ncc build --config=$(CONFIG) --build-source --log-level $(LOG_LEVEL) install: ncc package install --package=$(PACKAGE) --skip-dependencies --reinstall -y --log-level $(LOG_LEVEL) From b5874371b1f259fc3cece0ae05b9e85cf667ba8d Mon Sep 17 00:00:00 2001 From: netkas Date: Mon, 23 Sep 2024 13:53:02 -0400 Subject: [PATCH 3/7] Remove redundant --build-source flag from build steps --- .github/workflows/ci.yml | 8 ++++---- Makefile | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29623cd..b547f1b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,12 +46,12 @@ jobs: echo "NCC build directory not found" exit 1 fi - php "$NCC_DIR/INSTALL" --auto --install-composer + php "$NCC_DIR/INSTALL" --auto cd .. && rm -rf ncc - name: Build project run: | - ncc build --config release --build-source --log-level debug + ncc build --config release --log-level debug - name: Upload build artifacts uses: actions/upload-artifact@v4 @@ -106,12 +106,12 @@ jobs: echo "NCC build directory not found" exit 1 fi - php "$NCC_DIR/INSTALL" --auto --install-composer + php "$NCC_DIR/INSTALL" --auto cd .. && rm -rf ncc - name: Install NCC packages run: | - ncc package install --package="ncc-build/net.nosial.configlib.ncc" --reinstall -y --log-level debug + ncc package install --package="ncc-build/net.nosial.configlib.ncc" --build-source --reinstall -y --log-level debug - name: Run PHPUnit tests run: | diff --git a/Makefile b/Makefile index 86f53a1..5f919db 100644 --- a/Makefile +++ b/Makefile @@ -9,10 +9,10 @@ all: build # Build Steps build: - ncc build --config=$(CONFIG) --build-source --log-level $(LOG_LEVEL) + ncc build --config=$(CONFIG) --log-level $(LOG_LEVEL) install: - ncc package install --package=$(PACKAGE) --skip-dependencies --reinstall -y --log-level $(LOG_LEVEL) + ncc package install --package=$(PACKAGE) --skip-dependencies --build-source --reinstall -y --log-level $(LOG_LEVEL) clean: rm -rf build From 698e2cb334baf2aa6a5fd92fc7e542a6af3066d0 Mon Sep 17 00:00:00 2001 From: netkas Date: Mon, 23 Sep 2024 18:50:08 -0400 Subject: [PATCH 4/7] Updated ci.yml --- .github/workflows/ci.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b547f1b..7a33d55 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,6 +69,19 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 + - name: Check for phpunit.xml + id: file_check + run: | + if [ -f phpunit.xml ]; then + echo "::set-output name=exists::true" + else + echo "::set-output name=exists::false" + fi + + - name: Skip if no phpunit.xml + if: steps.file_check.outputs.exists == 'false' + run: exit 78 + - name: Download build artifacts uses: actions/download-artifact@v4 with: From 2f41614d209f1f5098cccde16268db9e093c6c31 Mon Sep 17 00:00:00 2001 From: netkas Date: Thu, 26 Sep 2024 14:57:27 -0400 Subject: [PATCH 5/7] Update version and improve config validation --- project.json | 2 +- src/ConfigLib/Configuration.php | 4 +--- tests/ConfigLib/ConfigurationTest.php | 4 +++- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/project.json b/project.json index f6ee0e6..5424afe 100644 --- a/project.json +++ b/project.json @@ -35,7 +35,7 @@ "company": "Nosial", "copyright": "Copyright (c) 2022-2023 Nosial", "description": "ConfigLib is a library for reading and writing configuration files via the NCC Runtime API", - "version": "1.1.0", + "version": "1.1.1", "uuid": "9347259e-8e4d-11ed-85a7-fd07cf28ef35" }, "build": { diff --git a/src/ConfigLib/Configuration.php b/src/ConfigLib/Configuration.php index 86ee637..62b604a 100644 --- a/src/ConfigLib/Configuration.php +++ b/src/ConfigLib/Configuration.php @@ -161,9 +161,7 @@ */ private static function validateKey(string $input): bool { - $pattern = '/^([a-zA-Z0-9]+\.?)+$/'; - - if (preg_match($pattern, $input)) + if (preg_match('/^([a-zA-Z0-9_]+\.?)+$/', $input)) { return true; } diff --git a/tests/ConfigLib/ConfigurationTest.php b/tests/ConfigLib/ConfigurationTest.php index a657551..2f8330b 100644 --- a/tests/ConfigLib/ConfigurationTest.php +++ b/tests/ConfigLib/ConfigurationTest.php @@ -52,8 +52,10 @@ class ConfigurationTest extends TestCase public function testGetMethodWithValidKey(): void { $config = new Configuration('test'); - $config->set('key1.key2', 'value'); + $this->assertTrue($config->set('key1.key2', 'value', true)); $this->assertEquals('value', $config->get('key1.key2')); + $this->assertTrue($config->set('foo.fizz_buzz', 'value', true)); + $this->assertEquals('value', $config->get('foo.fizz_buzz')); } /** From 489df9f79a0b60b502f9fd433741fa39fbeeec63 Mon Sep 17 00:00:00 2001 From: netkas Date: Thu, 26 Sep 2024 14:58:09 -0400 Subject: [PATCH 6/7] Updated CHANGELOG.md --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 449338a..dd8cb07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.1.1] - 2024-09-26 + +This update introduces a minor bug fix + +### Fixed + - Fixed issue where keys containing underscores are considered to be invalid + + ## [1.1.0] - 2024-09-23 This update introduces changes for PHP 8.3 & NCC 2.1.0+ compatibility From b8e83d31bc229d71ed5b1bb0f463a5e3104994df Mon Sep 17 00:00:00 2001 From: netkas Date: Fri, 27 Sep 2024 13:18:53 -0400 Subject: [PATCH 7/7] Fix configuration path resolution and add setup script --- CHANGELOG.md | 9 +++++ project.json | 16 ++++++++- setup | 14 ++++++++ src/ConfigLib/Configuration.php | 58 ++++++++++++++++++++++++++++++++- 4 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 setup diff --git a/CHANGELOG.md b/CHANGELOG.md index dd8cb07..02d7f1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.1.2] - 2024-09-27 + +This update fixes a critical bug where configuration files may not be found when using different user accounts, +especially when the configuration file is located in a directory that is not accessible by the user account running the +application. This was fixed by changing the way the configuration file path is resolved including by adding a setup +execution unit that will be executed post-installation to ensure that the configuration file is accessible by the user +account running the application. + + ## [1.1.1] - 2024-09-26 This update introduces a minor bug fix diff --git a/project.json b/project.json index 5424afe..c1797c0 100644 --- a/project.json +++ b/project.json @@ -27,15 +27,29 @@ "working_directory": "%CWD%", "tty": true } + }, + { + "name": "setup", + "runner": "php", + "execute": { + "target": "setup", + "working_directory": "%CWD%", + "tty": true + } } ], + "installer": { + "post_install": [ + "setup" + ] + }, "assembly": { "name": "ConfigLib", "package": "net.nosial.configlib", "company": "Nosial", "copyright": "Copyright (c) 2022-2023 Nosial", "description": "ConfigLib is a library for reading and writing configuration files via the NCC Runtime API", - "version": "1.1.1", + "version": "1.1.2", "uuid": "9347259e-8e4d-11ed-85a7-fd07cf28ef35" }, "build": { diff --git a/setup b/setup new file mode 100644 index 0000000..7c6b690 --- /dev/null +++ b/setup @@ -0,0 +1,14 @@ +path = $globalDir . DIRECTORY_SEPARATOR . $name . '.conf'; + } + if ($this->path === null) { - $filePath = $name . '.conf'; if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $configDir = getenv('APPDATA') ?: getenv('LOCALAPPDATA'); @@ -514,4 +520,54 @@ $fs->dumpFile($path, $this->toYaml()); $fs->chmod($path, 0777); } + + /** + * Retrieves the global directory path for configuration files. + * + * @return string The global directory path for configuration files. + */ + public static function getGlobalDirectory(): string + { + $path = DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . 'configlib'; + + if(file_exists($path) && is_writable($path)) + { + return $path; + } + + if((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')) + { + $variables = [ + 'SYSTEMDRIVE', + 'CSIDL_APPDATA', + 'CSIDL_PROGRAM_FILES' + ]; + + foreach($variables as $variable) + { + $environment_variable = getenv($variable); + if($environment_variable) + { + return $environment_variable . DIRECTORY_SEPARATOR . 'configlib'; + } + } + } + else + { + $variables = [ + 'HOME', + 'XDG_CONFIG_HOME', + 'XDG_DATA_HOME' + ]; + + foreach($variables as $variable) + { + $environment_variable = getenv($variable); + if($environment_variable) + { + return $environment_variable . DIRECTORY_SEPARATOR . 'configlib'; + } + } + } + } } \ No newline at end of file