Compare commits

..

14 commits
dev ... master

Author SHA1 Message Date
88ec33ff1a
Update CHANGELOG.md and Configuration class to use LogLib2
Some checks are pending
CI / release (push) Waiting to run
CI / debug (push) Waiting to run
CI / release-executable (push) Waiting to run
CI / debug-executable (push) Waiting to run
CI / release_executable (push) Waiting to run
CI / debug_executable (push) Waiting to run
CI / check-phpunit (push) Waiting to run
CI / check-phpdoc (push) Waiting to run
CI / generate-phpdoc (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / release-documentation (push) Blocked by required conditions
CI / release-artifacts (push) Blocked by required conditions
- Added entry for version 1.1.7 in CHANGELOG.md
- Updated remote references for dependencies
- Changed logger implementation in Configuration class to use LogLib2
2025-03-14 15:00:35 -04:00
bf71326090
Updated README.md
Some checks are pending
CI / release (push) Waiting to run
CI / debug (push) Waiting to run
CI / release-executable (push) Waiting to run
CI / debug-executable (push) Waiting to run
CI / release_executable (push) Waiting to run
CI / debug_executable (push) Waiting to run
CI / check-phpunit (push) Waiting to run
CI / check-phpdoc (push) Waiting to run
CI / generate-phpdoc (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / release-documentation (push) Blocked by required conditions
CI / release-artifacts (push) Blocked by required conditions
2025-03-11 14:24:20 -04:00
netkas
936485dde7 - 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
2025-01-07 21:14:03 -05:00
netkas
6966fd39d0 Bumped version to 1.1.6 2025-01-07 21:08:11 -05:00
netkas
09b2e88e1c Updated CHANGELOG.md 2024-12-27 15:33:59 -05:00
netkas
561064261c Version fast-forward 2024-12-27 15:32:00 -05:00
netkas
faad3e69de Minor correction 2024-12-27 15:30:08 -05:00
netkas
9e97a6d414 Refactor build process and streamline executable handling 2024-12-27 15:27:57 -05:00
netkas
015f13bf12 Updated CHANGELOG.md 2024-12-27 15:25:49 -05:00
netkas
514d527923 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	.idea/php.xml
#	CHANGELOG.md
#	project.json
#	src/ConfigLib/Configuration.php
2024-12-27 15:25:30 -05:00
netkas
489196267e Bumped version to 1.1.2 2024-12-27 15:20:56 -05:00
netkas
994d4092fc Updated project 2024-12-27 15:20:42 -05:00
netkas
579813315b Add support for CONFIGLIB_PATH environment variable 2024-12-27 15:20:36 -05:00
netkas
28d67deaa8 Deleted unused ci.yml 2024-10-29 00:30:11 -04:00
9 changed files with 223 additions and 476 deletions

View file

@ -1,158 +0,0 @@
name: CI
on:
push:
branches:
- 'master'
release:
types: [created]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
container:
image: php:8.3
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
apt update -yqq
apt install git libpq-dev libzip-dev zip make wget gnupg -yqq
- name: Install phive
run: |
wget -O phive.phar https://phar.io/releases/phive.phar
wget -O phive.phar.asc https://phar.io/releases/phive.phar.asc
gpg --keyserver hkps://keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79
gpg --verify phive.phar.asc phive.phar
chmod +x phive.phar
mv phive.phar /usr/local/bin/phive
- name: Install phab
run: |
phive install phpab --global --trust-gpg-keys 0x2A8299CE842DD38C
- name: Install latest version of NCC
run: |
git clone https://git.n64.cc/nosial/ncc.git
cd ncc
make redist
NCC_DIR=$(find build/ -type d -name "ncc_*" | head -n 1)
if [ -z "$NCC_DIR" ]; then
echo "NCC build directory not found"
exit 1
fi
php "$NCC_DIR/INSTALL" --auto
cd .. && rm -rf ncc
- name: Build project
run: |
ncc build --config release --log-level debug
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: ncc-build
path: build/release/net.nosial.configlib.ncc
test:
needs: build
runs-on: ubuntu-latest
container:
image: php:8.3
steps:
- 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:
name: ncc-build
path: ncc-build # Adjust this to download the artifact directly under 'ncc-build'
- name: Install dependencies
run: |
apt update -yqq
apt install git libpq-dev libzip-dev zip make wget gnupg -yqq
curl -sSLf -o /usr/local/bin/install-php-extensions https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions
chmod +x /usr/local/bin/install-php-extensions
install-php-extensions zip
- name: Install phive
run: |
wget -O phive.phar https://phar.io/releases/phive.phar
wget -O phive.phar.asc https://phar.io/releases/phive.phar.asc
gpg --keyserver hkps://keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79
gpg --verify phive.phar.asc phive.phar
chmod +x phive.phar
mv phive.phar /usr/local/bin/phive
- name: Install phab
run: |
phive install phpab --global --trust-gpg-keys 0x2A8299CE842DD38C
- name: Install latest version of NCC
run: |
git clone https://git.n64.cc/nosial/ncc.git
cd ncc
make redist
NCC_DIR=$(find build/ -type d -name "ncc_*" | head -n 1)
if [ -z "$NCC_DIR" ]; then
echo "NCC build directory not found"
exit 1
fi
php "$NCC_DIR/INSTALL" --auto
cd .. && rm -rf ncc
- name: Install NCC packages
run: |
ncc package install --package="ncc-build/net.nosial.configlib.ncc" --build-source --reinstall -y --log-level debug
- name: Run PHPUnit tests
run: |
wget https://phar.phpunit.de/phpunit-11.3.phar
php phpunit-11.3.phar --configuration phpunit.xml
release:
needs: [build, test]
permissions: write-all
runs-on: ubuntu-latest
container:
image: php:8.3
if: github.event_name == 'release'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: ncc-build
path: ncc-build
- name: Upload to GitHub Release
uses: softprops/action-gh-release@v1
with:
files: |
ncc-build/net.nosial.configlib.ncc
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View file

@ -51,7 +51,7 @@ jobs:
- name: Build project - name: Build project
run: | run: |
ncc build --config release --log-level debug ncc build --config release --build-source --log-level debug
- name: Upload build artifact - name: Upload build artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
@ -100,111 +100,13 @@ jobs:
- name: Build project - name: Build project
run: | run: |
ncc build --config debug --log-level debug ncc build --config debug --build-source --log-level debug
- name: Upload build artifact - name: Upload build artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: debug name: debug
path: build/debug/net.nosial.configlib.ncc path: build/debug/net.nosial.configlib.ncc
release-compressed:
runs-on: ubuntu-latest
container:
image: php:8.3
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
apt update -yqq
apt install git libpq-dev libzip-dev zip make wget gnupg -yqq
- name: Install phive
run: |
wget -O phive.phar https://phar.io/releases/phive.phar
wget -O phive.phar.asc https://phar.io/releases/phive.phar.asc
gpg --keyserver hkps://keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79
gpg --verify phive.phar.asc phive.phar
chmod +x phive.phar
mv phive.phar /usr/local/bin/phive
- name: Install phab
run: |
phive install phpab --global --trust-gpg-keys 0x2A8299CE842DD38C
- name: Install latest version of NCC
run: |
git clone https://git.n64.cc/nosial/ncc.git
cd ncc
make redist
NCC_DIR=$(find build/ -type d -name "ncc_*" | head -n 1)
if [ -z "$NCC_DIR" ]; then
echo "NCC build directory not found"
exit 1
fi
php "$NCC_DIR/INSTALL" --auto
cd .. && rm -rf ncc
- name: Build project
run: |
ncc build --config release-compressed --log-level debug
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: release-compressed
path: build/release/net.nosial.configlib.gz.ncc
debug-compressed:
runs-on: ubuntu-latest
container:
image: php:8.3
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
apt update -yqq
apt install git libpq-dev libzip-dev zip make wget gnupg -yqq
- name: Install phive
run: |
wget -O phive.phar https://phar.io/releases/phive.phar
wget -O phive.phar.asc https://phar.io/releases/phive.phar.asc
gpg --keyserver hkps://keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79
gpg --verify phive.phar.asc phive.phar
chmod +x phive.phar
mv phive.phar /usr/local/bin/phive
- name: Install phab
run: |
phive install phpab --global --trust-gpg-keys 0x2A8299CE842DD38C
- name: Install latest version of NCC
run: |
git clone https://git.n64.cc/nosial/ncc.git
cd ncc
make redist
NCC_DIR=$(find build/ -type d -name "ncc_*" | head -n 1)
if [ -z "$NCC_DIR" ]; then
echo "NCC build directory not found"
exit 1
fi
php "$NCC_DIR/INSTALL" --auto
cd .. && rm -rf ncc
- name: Build project
run: |
ncc build --config debug-compressed --log-level debug
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: debug-compressed
path: build/debug/net.nosial.configlib.gz.ncc
release-executable: release-executable:
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: container:
@ -247,7 +149,7 @@ jobs:
- name: Build project - name: Build project
run: | run: |
ncc build --config release-executable --log-level debug ncc build --config release-executable --build-source --log-level debug
- name: Upload build artifact - name: Upload build artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
@ -296,14 +198,14 @@ jobs:
- name: Build project - name: Build project
run: | run: |
ncc build --config debug-executable --log-level debug ncc build --config debug-executable --build-source --log-level debug
- name: Upload build artifact - name: Upload build artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: debug-executable name: debug-executable
path: build/debug/debug_executable_gz path: build/debug/debug_executable_gz
release-compressed-executable: release_executable:
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: container:
image: php:8.3 image: php:8.3
@ -345,14 +247,14 @@ jobs:
- name: Build project - name: Build project
run: | run: |
ncc build --config release-compressed-executable --log-level debug ncc build --config release_executable --build-source --log-level debug
- name: Upload build artifact - name: Upload build artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: release-compressed-executable name: release_executable
path: build/release/release_compressed_executable path: build/release/ConfigLib
debug-compressed-executable: debug_executable:
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: container:
image: php:8.3 image: php:8.3
@ -394,13 +296,13 @@ jobs:
- name: Build project - name: Build project
run: | run: |
ncc build --config debug-compressed-executable --log-level debug ncc build --config debug_executable --build-source --log-level debug
- name: Upload build artifact - name: Upload build artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: debug-compressed-executable name: debug_executable
path: build/debug/debug_compressed_executable path: build/debug/ConfigLib
# Checking for phpunit.xml # Checking for phpunit.xml
@ -471,7 +373,7 @@ jobs:
path: docs.zip path: docs.zip
test: test:
needs: [release, debug, release-compressed, debug-compressed, release-executable, debug-executable, release-compressed-executable, debug-compressed-executable, check-phpunit] needs: [release, debug, release-executable, debug-executable, release_executable, debug_executable, check-phpunit]
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: container:
image: php:8.3 image: php:8.3
@ -565,7 +467,7 @@ jobs:
release-artifacts: release-artifacts:
needs: [release, debug, release-compressed, debug-compressed, release-executable, debug-executable, release-compressed-executable, debug-compressed-executable] needs: [release, debug, release-executable, debug-executable, release_executable, debug_executable]
permissions: write-all permissions: write-all
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: container:
@ -600,30 +502,6 @@ jobs:
debug/* debug/*
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Download release-compressed artifact
uses: actions/download-artifact@v4
with:
name: release-compressed
path: release-compressed
- name: Upload release-compressed artifact to release
uses: softprops/action-gh-release@v1
with:
files: |
release-compressed/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Download debug-compressed artifact
uses: actions/download-artifact@v4
with:
name: debug-compressed
path: debug-compressed
- name: Upload debug-compressed artifact to release
uses: softprops/action-gh-release@v1
with:
files: |
debug-compressed/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Download release-executable artifact - name: Download release-executable artifact
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
with: with:
@ -648,27 +526,27 @@ jobs:
debug-executable/* debug-executable/*
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Download release-compressed-executable artifact - name: Download release_executable artifact
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
with: with:
name: release-compressed-executable name: release_executable
path: release-compressed-executable path: release_executable
- name: Upload release-compressed-executable artifact to release - name: Upload release_executable artifact to release
uses: softprops/action-gh-release@v1 uses: softprops/action-gh-release@v1
with: with:
files: | files: |
release-compressed-executable/* release_executable/*
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Download debug-compressed-executable artifact - name: Download debug_executable artifact
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
with: with:
name: debug-compressed-executable name: debug_executable
path: debug-compressed-executable path: debug_executable
- name: Upload debug-compressed-executable artifact to release - name: Upload debug_executable artifact to release
uses: softprops/action-gh-release@v1 uses: softprops/action-gh-release@v1
with: with:
files: | files: |
debug-compressed-executable/* debug_executable/*
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

14
.idea/php.xml generated
View file

@ -12,14 +12,11 @@
<component name="PhpIncludePathManager"> <component name="PhpIncludePathManager">
<include_path> <include_path>
<path value="/var/ncc/packages/net.nosial.optslib=1.1.2" /> <path value="/var/ncc/packages/net.nosial.optslib=1.1.2" />
<path value="/var/ncc/packages/net.nosial.loglib=1.1.1" /> <path value="/var/ncc/packages/net.nosial.loglib2=1.0.2" />
<path value="/var/ncc/packages/com.symfony.uid=v7.1.5" />
<path value="/var/ncc/packages/com.symfony.yaml=v7.1.5" /> <path value="/var/ncc/packages/com.symfony.yaml=v7.1.5" />
<path value="/var/ncc/packages/com.symfony.filesystem=v7.1.5" /> <path value="/var/ncc/packages/net.nosial.loglib=2.0.4" />
<path value="/var/ncc/packages/com.symfony.polyfill_ctype=v1.31.0" />
<path value="/var/ncc/packages/com.symfony.polyfill_mbstring=v1.31.0" /> <path value="/var/ncc/packages/com.symfony.polyfill_mbstring=v1.31.0" />
<path value="/var/ncc/packages/com.symfony.polyfill_uuid=v1.31.0" /> <path value="/var/ncc/packages/com.symfony.polyfill_ctype=v1.31.0" />
<path value="/var/ncc/packages/com.symfony.process=v7.1.5" />
<path value="/usr/share/ncc" /> <path value="/usr/share/ncc" />
<path value="/usr/share/php" /> <path value="/usr/share/php" />
</include_path> </include_path>
@ -28,12 +25,9 @@
<component name="PhpStanOptionsConfiguration"> <component name="PhpStanOptionsConfiguration">
<option name="transferred" value="true" /> <option name="transferred" value="true" />
</component> </component>
<component name="PhpTerminalSettingsCustomizer">
<option name="myIsInterpreterAdded" value="false" />
</component>
<component name="PhpUnit"> <component name="PhpUnit">
<phpunit_settings> <phpunit_settings>
<PhpUnitSettings load_method="PHPUNIT_PHAR" custom_loader_path="$USER_HOME$/phpunit.phar" phpunit_phar_path="$USER_HOME$/phpunit.phar" /> <PhpUnitSettings load_method="PHPUNIT_PHAR" custom_loader_path="$PROJECT_DIR$/../phpunit.phar" phpunit_phar_path="$PROJECT_DIR$/../phpunit.phar" />
</phpunit_settings> </phpunit_settings>
</component> </component>
<component name="PsalmOptionsConfiguration"> <component name="PsalmOptionsConfiguration">

View file

@ -5,6 +5,37 @@ 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/), 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). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.1.7] - 2025-03-14
This update introduces minor changes
### Changed
- Updated remote references for dependencies
- Updated Library to use net.nosial.loglib2 instead of the now deprecated net.nosial.loglib
## [1.1.6] - 2025-01-07
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
This update introduces minor improvements
### Added
- Add support for CONFIGLIB_PATH environment variable to specify the path to the configuration files directory
## [1.1.4] - 2024-10-29 ## [1.1.4] - 2024-10-29
This update introduces a minor bug fix This update introduces a minor bug fix
@ -13,13 +44,17 @@ This update introduces a minor bug fix
- Fixed regex pattern for configuration properties being considered invalid when they contain an underscore. - Fixed regex pattern for configuration properties being considered invalid when they contain an underscore.
## [1.1.3] - 2024-10-13 ## [1.1.3] - 2024-10-13
This update introduces a new build system This update introduces a new build system
## [1.1.2] - 2024-09-27 ## [1.1.2] - 2024-09-27
> This change has been reverted
This update fixes a critical bug where configuration files may not be found when using different user accounts, 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 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 application. This was fixed by changing the way the configuration file path is resolved including by adding a setup

View file

@ -1,20 +1,33 @@
# Variables # Variables
CONFIG ?= release DEFAULT_CONFIGURATION ?= release
LOG_LEVEL = debug LOG_LEVEL = debug
OUTDIR = build/$(CONFIG)
PACKAGE = $(OUTDIR)/net.nosial.configlib.ncc
# Default Target # Default Target
all: build all: release debug release-executable debug-executable release_executable debug_executable
# Build Steps # Build Steps
build: release:
ncc build --config=$(CONFIG) --log-level $(LOG_LEVEL) ncc build --config=release --log-level $(LOG_LEVEL)
debug:
ncc build --config=debug --log-level $(LOG_LEVEL)
release-executable:
ncc build --config=release-executable --log-level $(LOG_LEVEL)
debug-executable:
ncc build --config=debug-executable --log-level $(LOG_LEVEL)
release_executable:
ncc build --config=release_executable --log-level $(LOG_LEVEL)
debug_executable:
ncc build --config=debug_executable --log-level $(LOG_LEVEL)
install:
ncc package install --package=$(PACKAGE) --skip-dependencies --build-source --reinstall -y --log-level $(LOG_LEVEL) install: release
ncc package install --package=build/release/net.nosial.configlib.ncc --skip-dependencies --build-source --reinstall -y --log-level $(LOG_LEVEL)
test: release
[ -f phpunit.xml ] || { echo "phpunit.xml not found"; exit 1; }
phpunit
clean: clean:
rm -rf build rm -rf build
.PHONY: all build install clean .PHONY: all install test clean release debug release-executable debug-executable release_executable debug_executable

View file

@ -9,10 +9,25 @@ be configured more easily by following the documented instructions on how to alt
could use a builtin editor to edit the configuration file manually. could use a builtin editor to edit the configuration file manually.
## Community
This project and many others from Nosial are available on multiple publicly available and free git repositories at
- [n64](https://git.n64.cc/nosial/configlib)
- [GitHub](https://github.com/nosial/configlib)
- [Codeberg](https://codeberg.org/nosial/configlib)
Issues & Pull Requests are frequently checked and to be referenced accordingly in commits and changes, Nosial remains
dedicated to keep these repositories up to date when possible.
For questions & discussions see the public Telegram community at [@NosialDiscussions](https://t.me/NosialDiscussions).
We do encourage community support and discussions, please be respectful and follow the rules of the community.
## Table of contents ## Table of contents
<!-- TOC --> <!-- TOC -->
* [ConfigLib](#configlib) * [ConfigLib](#configlib)
* [Community](#community)
* [Table of contents](#table-of-contents) * [Table of contents](#table-of-contents)
* [Installation](#installation) * [Installation](#installation)
* [Compile from source](#compile-from-source) * [Compile from source](#compile-from-source)

24
main
View file

@ -1,6 +1,24 @@
<?php <?php
require('ncc'); if (PHP_SAPI !== 'cli')
import('net.nosial.configlib', 'latest'); {
print('net.nosial.configlib must be run from the command line.' . PHP_EOL);
exit(1);
}
\ConfigLib\Program::main(); if(!isset($argv))
{
if(isset($_SERVER['argv']))
{
$argv = $_SERVER['argv'];
}
else
{
print('net.nosial.configlib failed to run, no $argv found.' . PHP_EOL);
exit(1);
}
}
require('ncc');
\ncc\Classes\Runtime::import('net.nosial.configlib', 'latest');
exit(\ConfigLib\Program::main($argv));

View file

@ -24,13 +24,13 @@
"description": "ConfigLib is a library for reading and writing configuration files via the NCC Runtime API", "description": "ConfigLib is a library for reading and writing configuration files via the NCC Runtime API",
"company": "Nosial", "company": "Nosial",
"copyright": "Copyright (c) 2022-2023 Nosial", "copyright": "Copyright (c) 2022-2023 Nosial",
"version": "1.1.4", "version": "1.1.7",
"uuid": "9347259e-8e4d-11ed-85a7-fd07cf28ef35" "uuid": "9347259e-8e4d-11ed-85a7-fd07cf28ef35"
}, },
"build": { "build": {
"source_path": "src", "source_path": "src",
"default_configuration": "release", "default_configuration": "release",
"main": "main", "main": "main_policy",
"define_constants": { "define_constants": {
"VERSION": "%ASSEMBLY.VERSION%" "VERSION": "%ASSEMBLY.VERSION%"
}, },
@ -38,12 +38,12 @@
{ {
"name": "net.nosial.optslib", "name": "net.nosial.optslib",
"version": "latest", "version": "latest",
"source": "nosial/libs.opts=latest@n64" "source": "nosial/optslib=latest@github"
}, },
{ {
"name": "net.nosial.loglib", "name": "net.nosial.loglib2",
"version": "latest", "version": "latest",
"source": "nosial/libs.log=latest@n64" "source": "nosial/loglib2=latest@github"
}, },
{ {
"name": "com.symfony.filesystem", "name": "com.symfony.filesystem",
@ -75,25 +75,6 @@
"DEBUG": "1" "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", "name": "release-executable",
"build_type": "executable", "build_type": "executable",
@ -111,26 +92,24 @@
} }
}, },
{ {
"name": "release-compressed-executable", "name": "release_executable",
"build_type": "executable", "build_type": "executable",
"output": "build/release/release_compressed_executable", "output": "build/release/%ASSEMBLY.NAME%",
"options": { "options": {
"ncc_configuration": "release-compressed" "ncc_configuration": "release"
} }
}, },
{ {
"name": "debug-compressed-executable", "name": "debug_executable",
"build_type": "executable", "build_type": "executable",
"output": "build/debug/debug_compressed_executable", "output": "build/debug/%ASSEMBLY.NAME%",
"options": { "options": {
"ncc_configuration": "debug-compressed" "ncc_configuration": "debug"
}
}
]
}, },
"installer": { "define_constants": {
"post_install": [ "DEBUG": "1"
"setup" }
}
] ]
}, },
"execution_policies": [ "execution_policies": [
@ -147,7 +126,7 @@
} }
}, },
{ {
"name": "setup", "name": "main_policy",
"runner": "php", "runner": "php",
"execute": { "execute": {
"working_directory": "%CWD%", "working_directory": "%CWD%",
@ -155,7 +134,7 @@
"tty": true, "tty": true,
"timeout": null, "timeout": null,
"idle_timeout": null, "idle_timeout": null,
"target": "setup" "target": "main"
} }
} }
] ]

View file

@ -1,11 +1,9 @@
<?php <?php
/** @noinspection PhpMissingFieldTypeInspection */
namespace ConfigLib; namespace ConfigLib;
use Exception; use Exception;
use LogLib\Log; use LogLib2\Logger;
use RuntimeException; use RuntimeException;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
@ -13,45 +11,51 @@
class Configuration class Configuration
{ {
/** /**
* The name of the configuration * The logger of the class
* * @var Logger
* @var string
*/ */
private $name; private Logger $logger;
/**
* The name of the configuration
* @var string|array
*/
private string|array $name;
/** /**
* The path to the configuration file * The path to the configuration file
* * @var string|null
* @var string
*/ */
private $path; private ?string $path;
/** /**
* The configuration data * The configuration data
*
* @var array * @var array
*/ */
private $configuration; private array $configuration;
/** /**
* Indicates if the current instance is modified * Indicates if the current instance is modified
*
* @var bool * @var bool
*/ */
private $modified; private bool $modified;
/** /**
* Public Constructor * Public Constructor
* *
* @param string $name The name of the configuration (e.g. "MyApp" or "net.example.myapp") * @param string $name The name of the configuration (e.g. "MyApp" or "net.example.myapp")
* @param string|null $path The directory where the configuration file will be stored
*/ */
public function __construct(string $name='default') public function __construct(string $name='default', ?string $path=null)
{ {
$this->logger = new Logger('net.nosial.configlib');
// Sanitize $name for a file path // Sanitize $name for a file path
$name = strtolower($name); $name = strtolower($name);
$name = str_replace(array('/', '\\', '.'), '_', $name); $name = str_replace(array('/', '\\', '.'), '_', $name);
$env = getenv(sprintf("CONFIGLIB_%s", strtoupper($name))); $env = getenv(sprintf("CONFIGLIB_%s", strtoupper($name)));
$this->path = null;
if($env !== false) if($env !== false)
{ {
if(file_exists($env)) if(file_exists($env))
@ -60,18 +64,35 @@
} }
else else
{ {
Log::warning('net.nosial.configlib', sprintf('Environment variable "%s" points to a non-existent file, resorting to default/builtin configuration', $env)); $this->logger->warning(sprintf('Environment variable "%s" points to a non-existent file, resorting to default/builtin configuration', $env));
} }
} }
$filePath = $name . '.conf'; if($path !== null)
$globalDir = self::getGlobalDirectory();
if(is_dir($globalDir) && is_writable($globalDir))
{ {
$this->path = $globalDir . DIRECTORY_SEPARATOR . $name . '.conf'; 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) if ($this->path === null)
{
$filePath = $name . '.conf';
// If the CONFIGLIB_PATH environment variable is set, use it as the configuration path
if(getenv('CONFIGLIB_PATH'))
{
$configDir = getenv('CONFIGLIB_PATH');
}
else
{ {
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
{ {
@ -118,10 +139,11 @@
if (!$configDir) if (!$configDir)
{ {
Log::warning('net.nosial.configlib', sprintf('Unable to find a proper directory to store configuration paths in, using temporary directory instead: %s', sys_get_temp_dir())); $this->logger->warning(sprintf('Unable to find a proper directory to store configuration paths in, using temporary directory instead: %s', sys_get_temp_dir()));
$configDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'configlib'; $configDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'configlib';
} }
} }
}
// Ensure the directory exists // Ensure the directory exists
if (!file_exists($configDir)) if (!file_exists($configDir))
@ -149,7 +171,7 @@
} }
catch(Exception $e) catch(Exception $e)
{ {
Log::error('net.nosial.configlib', sprintf('Unable to load configuration "%s", %s', $this->name, $e->getMessage())); $this->logger->error(sprintf('Unable to load configuration "%s", %s', $this->name, $e->getMessage()), $e);
throw new RuntimeException(sprintf('Unable to load configuration "%s"', $this->name), $e); throw new RuntimeException(sprintf('Unable to load configuration "%s"', $this->name), $e);
} }
} }
@ -171,6 +193,7 @@
{ {
return true; return true;
} }
return false; return false;
} }
@ -340,7 +363,7 @@
} }
$this->modified = false; $this->modified = false;
Log::debug('net.nosial.configlib', sprintf('Configuration "%s" saved', $this->name)); $this->logger->debug(sprintf('Configuration "%s" saved', $this->name));
} }
/** /**
@ -422,7 +445,7 @@
} }
$this->modified = false; $this->modified = false;
Log::debug('net.nosial.configlib', 'Loaded configuration file: ' . $this->path); $this->logger->debug('Loaded configuration file: ' . $this->path);
} }
/** /**
@ -480,7 +503,7 @@
} }
catch(Exception $e) catch(Exception $e)
{ {
Log::error('net.nosial.configlib', sprintf('Unable to save configuration "%s" to disk, %s', $this->name, $e->getMessage())); $this->logger->error(sprintf('Unable to save configuration "%s" to disk, %s', $this->name, $e->getMessage()), $e);
} }
} }
} }
@ -519,54 +542,4 @@
$fs->dumpFile($path, $this->toYaml()); $fs->dumpFile($path, $this->toYaml());
$fs->chmod($path, 0777); $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';
}
}
}
}
} }