Compare commits
No commits in common. "master" and "dev" have entirely different histories.
9 changed files with 473 additions and 220 deletions
158
.github/workflows/ci.yml
vendored
Normal file
158
.github/workflows/ci.yml
vendored
Normal file
|
@ -0,0 +1,158 @@
|
|||
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 }}
|
170
.github/workflows/ncc_workflow.yml
vendored
170
.github/workflows/ncc_workflow.yml
vendored
|
@ -51,7 +51,7 @@ jobs:
|
|||
|
||||
- name: Build project
|
||||
run: |
|
||||
ncc build --config release --build-source --log-level debug
|
||||
ncc build --config release --log-level debug
|
||||
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
|
@ -100,13 +100,111 @@ jobs:
|
|||
|
||||
- name: Build project
|
||||
run: |
|
||||
ncc build --config debug --build-source --log-level debug
|
||||
ncc build --config debug --log-level debug
|
||||
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: debug
|
||||
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:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
|
@ -149,7 +247,7 @@ jobs:
|
|||
|
||||
- name: Build project
|
||||
run: |
|
||||
ncc build --config release-executable --build-source --log-level debug
|
||||
ncc build --config release-executable --log-level debug
|
||||
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
|
@ -198,14 +296,14 @@ jobs:
|
|||
|
||||
- name: Build project
|
||||
run: |
|
||||
ncc build --config debug-executable --build-source --log-level debug
|
||||
ncc build --config debug-executable --log-level debug
|
||||
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: debug-executable
|
||||
path: build/debug/debug_executable_gz
|
||||
release_executable:
|
||||
release-compressed-executable:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: php:8.3
|
||||
|
@ -247,14 +345,14 @@ jobs:
|
|||
|
||||
- name: Build project
|
||||
run: |
|
||||
ncc build --config release_executable --build-source --log-level debug
|
||||
ncc build --config release-compressed-executable --log-level debug
|
||||
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: release_executable
|
||||
path: build/release/ConfigLib
|
||||
debug_executable:
|
||||
name: release-compressed-executable
|
||||
path: build/release/release_compressed_executable
|
||||
debug-compressed-executable:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: php:8.3
|
||||
|
@ -296,13 +394,13 @@ jobs:
|
|||
|
||||
- name: Build project
|
||||
run: |
|
||||
ncc build --config debug_executable --build-source --log-level debug
|
||||
ncc build --config debug-compressed-executable --log-level debug
|
||||
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: debug_executable
|
||||
path: build/debug/ConfigLib
|
||||
name: debug-compressed-executable
|
||||
path: build/debug/debug_compressed_executable
|
||||
|
||||
|
||||
# Checking for phpunit.xml
|
||||
|
@ -373,7 +471,7 @@ jobs:
|
|||
path: docs.zip
|
||||
|
||||
test:
|
||||
needs: [release, debug, release-executable, debug-executable, release_executable, debug_executable, check-phpunit]
|
||||
needs: [release, debug, release-compressed, debug-compressed, release-executable, debug-executable, release-compressed-executable, debug-compressed-executable, check-phpunit]
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: php:8.3
|
||||
|
@ -467,7 +565,7 @@ jobs:
|
|||
|
||||
|
||||
release-artifacts:
|
||||
needs: [release, debug, release-executable, debug-executable, release_executable, debug_executable]
|
||||
needs: [release, debug, release-compressed, debug-compressed, release-executable, debug-executable, release-compressed-executable, debug-compressed-executable]
|
||||
permissions: write-all
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
|
@ -502,6 +600,30 @@ jobs:
|
|||
debug/*
|
||||
env:
|
||||
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
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
|
@ -526,27 +648,27 @@ jobs:
|
|||
debug-executable/*
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Download release_executable artifact
|
||||
- name: Download release-compressed-executable artifact
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: release_executable
|
||||
path: release_executable
|
||||
- name: Upload release_executable artifact to release
|
||||
name: release-compressed-executable
|
||||
path: release-compressed-executable
|
||||
- name: Upload release-compressed-executable artifact to release
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
files: |
|
||||
release_executable/*
|
||||
release-compressed-executable/*
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Download debug_executable artifact
|
||||
- name: Download debug-compressed-executable artifact
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: debug_executable
|
||||
path: debug_executable
|
||||
- name: Upload debug_executable artifact to release
|
||||
name: debug-compressed-executable
|
||||
path: debug-compressed-executable
|
||||
- name: Upload debug-compressed-executable artifact to release
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
files: |
|
||||
debug_executable/*
|
||||
debug-compressed-executable/*
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
|
14
.idea/php.xml
generated
14
.idea/php.xml
generated
|
@ -12,11 +12,14 @@
|
|||
<component name="PhpIncludePathManager">
|
||||
<include_path>
|
||||
<path value="/var/ncc/packages/net.nosial.optslib=1.1.2" />
|
||||
<path value="/var/ncc/packages/net.nosial.loglib2=1.0.2" />
|
||||
<path value="/var/ncc/packages/net.nosial.loglib=1.1.1" />
|
||||
<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/net.nosial.loglib=2.0.4" />
|
||||
<path value="/var/ncc/packages/com.symfony.polyfill_mbstring=v1.31.0" />
|
||||
<path value="/var/ncc/packages/com.symfony.filesystem=v7.1.5" />
|
||||
<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_uuid=v1.31.0" />
|
||||
<path value="/var/ncc/packages/com.symfony.process=v7.1.5" />
|
||||
<path value="/usr/share/ncc" />
|
||||
<path value="/usr/share/php" />
|
||||
</include_path>
|
||||
|
@ -25,9 +28,12 @@
|
|||
<component name="PhpStanOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PhpTerminalSettingsCustomizer">
|
||||
<option name="myIsInterpreterAdded" value="false" />
|
||||
</component>
|
||||
<component name="PhpUnit">
|
||||
<phpunit_settings>
|
||||
<PhpUnitSettings load_method="PHPUNIT_PHAR" custom_loader_path="$PROJECT_DIR$/../phpunit.phar" phpunit_phar_path="$PROJECT_DIR$/../phpunit.phar" />
|
||||
<PhpUnitSettings load_method="PHPUNIT_PHAR" custom_loader_path="$USER_HOME$/phpunit.phar" phpunit_phar_path="$USER_HOME$/phpunit.phar" />
|
||||
</phpunit_settings>
|
||||
</component>
|
||||
<component name="PsalmOptionsConfiguration">
|
||||
|
|
37
CHANGELOG.md
37
CHANGELOG.md
|
@ -5,44 +5,12 @@ 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.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
|
||||
|
||||
This update introduces a minor bug fix
|
||||
|
||||
### Fixed
|
||||
- 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
|
||||
|
@ -50,11 +18,8 @@ This update introduces a minor bug fix
|
|||
This update introduces a new build system
|
||||
|
||||
|
||||
|
||||
## [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,
|
||||
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
|
||||
|
|
31
Makefile
31
Makefile
|
@ -1,33 +1,20 @@
|
|||
# Variables
|
||||
DEFAULT_CONFIGURATION ?= release
|
||||
CONFIG ?= release
|
||||
LOG_LEVEL = debug
|
||||
OUTDIR = build/$(CONFIG)
|
||||
PACKAGE = $(OUTDIR)/net.nosial.configlib.ncc
|
||||
|
||||
# Default Target
|
||||
all: release debug release-executable debug-executable release_executable debug_executable
|
||||
all: build
|
||||
|
||||
# Build Steps
|
||||
release:
|
||||
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)
|
||||
build:
|
||||
ncc build --config=$(CONFIG) --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
|
||||
install:
|
||||
ncc package install --package=$(PACKAGE) --skip-dependencies --build-source --reinstall -y --log-level $(LOG_LEVEL)
|
||||
|
||||
clean:
|
||||
rm -rf build
|
||||
|
||||
.PHONY: all install test clean release debug release-executable debug-executable release_executable debug_executable
|
||||
.PHONY: all build install clean
|
15
README.md
15
README.md
|
@ -9,25 +9,10 @@ be configured more easily by following the documented instructions on how to alt
|
|||
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
|
||||
|
||||
<!-- TOC -->
|
||||
* [ConfigLib](#configlib)
|
||||
* [Community](#community)
|
||||
* [Table of contents](#table-of-contents)
|
||||
* [Installation](#installation)
|
||||
* [Compile from source](#compile-from-source)
|
||||
|
|
24
main
24
main
|
@ -1,24 +1,6 @@
|
|||
<?php
|
||||
|
||||
if (PHP_SAPI !== 'cli')
|
||||
{
|
||||
print('net.nosial.configlib must be run from the command line.' . PHP_EOL);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
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));
|
||||
import('net.nosial.configlib', 'latest');
|
||||
|
||||
\ConfigLib\Program::main();
|
55
project.json
55
project.json
|
@ -24,13 +24,13 @@
|
|||
"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.7",
|
||||
"version": "1.1.4",
|
||||
"uuid": "9347259e-8e4d-11ed-85a7-fd07cf28ef35"
|
||||
},
|
||||
"build": {
|
||||
"source_path": "src",
|
||||
"default_configuration": "release",
|
||||
"main": "main_policy",
|
||||
"main": "main",
|
||||
"define_constants": {
|
||||
"VERSION": "%ASSEMBLY.VERSION%"
|
||||
},
|
||||
|
@ -38,12 +38,12 @@
|
|||
{
|
||||
"name": "net.nosial.optslib",
|
||||
"version": "latest",
|
||||
"source": "nosial/optslib=latest@github"
|
||||
"source": "nosial/libs.opts=latest@n64"
|
||||
},
|
||||
{
|
||||
"name": "net.nosial.loglib2",
|
||||
"name": "net.nosial.loglib",
|
||||
"version": "latest",
|
||||
"source": "nosial/loglib2=latest@github"
|
||||
"source": "nosial/libs.log=latest@n64"
|
||||
},
|
||||
{
|
||||
"name": "com.symfony.filesystem",
|
||||
|
@ -75,6 +75,25 @@
|
|||
"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",
|
||||
|
@ -92,24 +111,26 @@
|
|||
}
|
||||
},
|
||||
{
|
||||
"name": "release_executable",
|
||||
"name": "release-compressed-executable",
|
||||
"build_type": "executable",
|
||||
"output": "build/release/%ASSEMBLY.NAME%",
|
||||
"output": "build/release/release_compressed_executable",
|
||||
"options": {
|
||||
"ncc_configuration": "release"
|
||||
"ncc_configuration": "release-compressed"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "debug_executable",
|
||||
"name": "debug-compressed-executable",
|
||||
"build_type": "executable",
|
||||
"output": "build/debug/%ASSEMBLY.NAME%",
|
||||
"output": "build/debug/debug_compressed_executable",
|
||||
"options": {
|
||||
"ncc_configuration": "debug"
|
||||
"ncc_configuration": "debug-compressed"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"define_constants": {
|
||||
"DEBUG": "1"
|
||||
}
|
||||
}
|
||||
"installer": {
|
||||
"post_install": [
|
||||
"setup"
|
||||
]
|
||||
},
|
||||
"execution_policies": [
|
||||
|
@ -126,7 +147,7 @@
|
|||
}
|
||||
},
|
||||
{
|
||||
"name": "main_policy",
|
||||
"name": "setup",
|
||||
"runner": "php",
|
||||
"execute": {
|
||||
"working_directory": "%CWD%",
|
||||
|
@ -134,7 +155,7 @@
|
|||
"tty": true,
|
||||
"timeout": null,
|
||||
"idle_timeout": null,
|
||||
"target": "main"
|
||||
"target": "setup"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
@ -1,61 +1,57 @@
|
|||
<?php
|
||||
|
||||
/** @noinspection PhpMissingFieldTypeInspection */
|
||||
|
||||
namespace ConfigLib;
|
||||
|
||||
use Exception;
|
||||
use LogLib2\Logger;
|
||||
use LogLib\Log;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class Configuration
|
||||
{
|
||||
/**
|
||||
* The logger of the class
|
||||
* @var Logger
|
||||
*/
|
||||
private Logger $logger;
|
||||
|
||||
/**
|
||||
* The name of the configuration
|
||||
* @var string|array
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private string|array $name;
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* The path to the configuration file
|
||||
* @var string|null
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private ?string $path;
|
||||
private $path;
|
||||
|
||||
/**
|
||||
* The configuration data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private array $configuration;
|
||||
private $configuration;
|
||||
|
||||
/**
|
||||
* Indicates if the current instance is modified
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private bool $modified;
|
||||
private $modified;
|
||||
|
||||
/**
|
||||
* Public Constructor
|
||||
*
|
||||
* @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', ?string $path=null)
|
||||
public function __construct(string $name='default')
|
||||
{
|
||||
$this->logger = new Logger('net.nosial.configlib');
|
||||
|
||||
// Sanitize $name for a file path
|
||||
$name = strtolower($name);
|
||||
$name = str_replace(array('/', '\\', '.'), '_', $name);
|
||||
$env = getenv(sprintf("CONFIGLIB_%s", strtoupper($name)));
|
||||
$this->path = null;
|
||||
|
||||
$env = getenv(sprintf("CONFIGLIB_%s", strtoupper($name)));
|
||||
if($env !== false)
|
||||
{
|
||||
if(file_exists($env))
|
||||
|
@ -64,35 +60,18 @@
|
|||
}
|
||||
else
|
||||
{
|
||||
$this->logger->warning(sprintf('Environment variable "%s" points to a non-existent file, resorting to default/builtin configuration', $env));
|
||||
Log::warning('net.nosial.configlib', sprintf('Environment variable "%s" points to a non-existent file, resorting to default/builtin configuration', $env));
|
||||
}
|
||||
}
|
||||
|
||||
if($path !== null)
|
||||
$filePath = $name . '.conf';
|
||||
$globalDir = self::getGlobalDirectory();
|
||||
if(is_dir($globalDir) && is_writable($globalDir))
|
||||
{
|
||||
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;
|
||||
$this->path = $globalDir . DIRECTORY_SEPARATOR . $name . '.conf';
|
||||
}
|
||||
|
||||
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')
|
||||
{
|
||||
|
@ -139,11 +118,10 @@
|
|||
|
||||
if (!$configDir)
|
||||
{
|
||||
$this->logger->warning(sprintf('Unable to find a proper directory to store configuration paths in, using temporary directory instead: %s', sys_get_temp_dir()));
|
||||
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()));
|
||||
$configDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'configlib';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure the directory exists
|
||||
if (!file_exists($configDir))
|
||||
|
@ -171,7 +149,7 @@
|
|||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
$this->logger->error(sprintf('Unable to load configuration "%s", %s', $this->name, $e->getMessage()), $e);
|
||||
Log::error('net.nosial.configlib', sprintf('Unable to load configuration "%s", %s', $this->name, $e->getMessage()));
|
||||
throw new RuntimeException(sprintf('Unable to load configuration "%s"', $this->name), $e);
|
||||
}
|
||||
}
|
||||
|
@ -193,7 +171,6 @@
|
|||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -363,7 +340,7 @@
|
|||
}
|
||||
|
||||
$this->modified = false;
|
||||
$this->logger->debug(sprintf('Configuration "%s" saved', $this->name));
|
||||
Log::debug('net.nosial.configlib', sprintf('Configuration "%s" saved', $this->name));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -445,7 +422,7 @@
|
|||
}
|
||||
|
||||
$this->modified = false;
|
||||
$this->logger->debug('Loaded configuration file: ' . $this->path);
|
||||
Log::debug('net.nosial.configlib', 'Loaded configuration file: ' . $this->path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -503,7 +480,7 @@
|
|||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
$this->logger->error(sprintf('Unable to save configuration "%s" to disk, %s', $this->name, $e->getMessage()), $e);
|
||||
Log::error('net.nosial.configlib', sprintf('Unable to save configuration "%s" to disk, %s', $this->name, $e->getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -542,4 +519,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';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue