Merge branch 'master' into dev
# Conflicts: # .github/workflows/ci.yml # CHANGELOG.md # Makefile # project.json
This commit is contained in:
commit
af03b4ffda
5 changed files with 143 additions and 78 deletions
34
CHANGELOG.md
34
CHANGELOG.md
|
@ -5,9 +5,39 @@ 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-10-13
|
||||
## [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
|
||||
|
||||
### 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
|
||||
|
||||
### 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
|
||||
|
||||
This update introduces a new build system
|
||||
|
||||
|
||||
## [1.0.4] - 2023-08-12
|
||||
|
|
107
project.json
107
project.json
|
@ -5,9 +5,6 @@
|
|||
"minimum_version": "8.0",
|
||||
"maximum_version": "8.2"
|
||||
},
|
||||
"options": {
|
||||
"create_symlink": true
|
||||
},
|
||||
"update_source": {
|
||||
"source": "nosial/libs.config@n64",
|
||||
"repository": {
|
||||
|
@ -16,15 +13,43 @@
|
|||
"host": "git.n64.cc",
|
||||
"ssl": true
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"create_symlink": true
|
||||
}
|
||||
},
|
||||
"execution_policies":[
|
||||
{
|
||||
"name": "main",
|
||||
"runner": "php",
|
||||
"execute": {
|
||||
"target": "main",
|
||||
"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",
|
||||
"description": "ConfigLib is a library for reading and writing configuration files via the NCC Runtime API",
|
||||
"company": "Nosial",
|
||||
"copyright": "Copyright (c) 2022-2023 Nosial",
|
||||
"version": "1.1.1",
|
||||
"description": "ConfigLib is a library for reading and writing configuration files via the NCC Runtime API",
|
||||
"version": "1.1.2",
|
||||
"uuid": "9347259e-8e4d-11ed-85a7-fd07cf28ef35"
|
||||
},
|
||||
"build": {
|
||||
|
@ -38,26 +63,31 @@
|
|||
{
|
||||
"name": "net.nosial.optslib",
|
||||
"version": "latest",
|
||||
"source_type": "remote",
|
||||
"source": "nosial/libs.opts=latest@n64"
|
||||
},
|
||||
{
|
||||
"name": "net.nosial.loglib",
|
||||
"version": "latest",
|
||||
"source_type": "remote",
|
||||
"source": "nosial/libs.log=latest@n64"
|
||||
},
|
||||
{
|
||||
"name": "com.symfony.filesystem",
|
||||
"version": "latest",
|
||||
"source_type": "remote",
|
||||
"source": "symfony/filesystem=latest@packagist"
|
||||
},
|
||||
{
|
||||
"name": "com.symfony.yaml",
|
||||
"version": "latest",
|
||||
"source_type": "remote",
|
||||
"source": "symfony/yaml=latest@packagist"
|
||||
},
|
||||
{
|
||||
"name": "com.symfony.process",
|
||||
"version": "latest",
|
||||
"source_type": "remote",
|
||||
"source": "symfony/process=latest@packagist"
|
||||
}
|
||||
],
|
||||
|
@ -74,72 +104,7 @@
|
|||
"define_constants": {
|
||||
"DEBUG": "1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "release-compressed",
|
||||
"build_type": "ncc",
|
||||
"output": "build/release/%ASSEMBLY.PACKAGE%.gz.ncc",
|
||||
"options": {
|
||||
"compression": "high"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "debug-compressed",
|
||||
"build_type": "ncc",
|
||||
"output": "build/debug/%ASSEMBLY.PACKAGE%.gz.ncc",
|
||||
"options": {
|
||||
"compression": "high"
|
||||
},
|
||||
"define_constants": {
|
||||
"DEBUG": "1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "release-executable",
|
||||
"build_type": "executable",
|
||||
"output": "build/release/release_executable_gz",
|
||||
"options": {
|
||||
"ncc_configuration": "release"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "debug-executable",
|
||||
"build_type": "executable",
|
||||
"output": "build/debug/debug_executable_gz",
|
||||
"options": {
|
||||
"ncc_configuration": "debug"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "release-compressed-executable",
|
||||
"build_type": "executable",
|
||||
"output": "build/release/release_compressed_executable",
|
||||
"options": {
|
||||
"ncc_configuration": "release-compressed"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "debug-compressed-executable",
|
||||
"build_type": "executable",
|
||||
"output": "build/debug/debug_compressed_executable",
|
||||
"options": {
|
||||
"ncc_configuration": "debug-compressed"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"execution_policies": [
|
||||
{
|
||||
"name": "main",
|
||||
"runner": "php",
|
||||
"execute": {
|
||||
"working_directory": "%CWD%",
|
||||
"silent": false,
|
||||
"tty": true,
|
||||
"timeout": null,
|
||||
"idle_timeout": null,
|
||||
"target": "main"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
14
setup
Normal file
14
setup
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
$global_directory = $path = DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . 'configlib';
|
||||
|
||||
//try creating the directory if it doesn't exist
|
||||
if(!file_exists($global_directory))
|
||||
{
|
||||
if(!mkdir($global_directory, 0777, true))
|
||||
{
|
||||
exit('Failed to create global directory');
|
||||
}
|
||||
|
||||
chmod($global_directory, 0777);
|
||||
}
|
|
@ -64,9 +64,15 @@
|
|||
}
|
||||
}
|
||||
|
||||
$filePath = $name . '.conf';
|
||||
$globalDir = self::getGlobalDirectory();
|
||||
if(is_dir($globalDir) && is_writable($globalDir))
|
||||
{
|
||||
$this->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');
|
||||
|
@ -161,9 +167,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;
|
||||
}
|
||||
|
@ -516,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';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue