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
|
- name: Build project
|
||||||
run: |
|
run: |
|
||||||
ncc build --config release --build-source --log-level debug
|
ncc build --config release --log-level debug
|
||||||
|
|
||||||
- name: Upload build artifact
|
- name: Upload build artifact
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
|
@ -100,13 +100,111 @@ jobs:
|
||||||
|
|
||||||
- name: Build project
|
- name: Build project
|
||||||
run: |
|
run: |
|
||||||
ncc build --config debug --build-source --log-level debug
|
ncc build --config debug --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:
|
||||||
|
@ -149,7 +247,7 @@ jobs:
|
||||||
|
|
||||||
- name: Build project
|
- name: Build project
|
||||||
run: |
|
run: |
|
||||||
ncc build --config release-executable --build-source --log-level debug
|
ncc build --config release-executable --log-level debug
|
||||||
|
|
||||||
- name: Upload build artifact
|
- name: Upload build artifact
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
|
@ -198,14 +296,14 @@ jobs:
|
||||||
|
|
||||||
- name: Build project
|
- name: Build project
|
||||||
run: |
|
run: |
|
||||||
ncc build --config debug-executable --build-source --log-level debug
|
ncc build --config debug-executable --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_executable:
|
release-compressed-executable:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
image: php:8.3
|
image: php:8.3
|
||||||
|
@ -247,14 +345,14 @@ jobs:
|
||||||
|
|
||||||
- name: Build project
|
- name: Build project
|
||||||
run: |
|
run: |
|
||||||
ncc build --config release_executable --build-source --log-level debug
|
ncc build --config release-compressed-executable --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_executable
|
name: release-compressed-executable
|
||||||
path: build/release/ConfigLib
|
path: build/release/release_compressed_executable
|
||||||
debug_executable:
|
debug-compressed-executable:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
image: php:8.3
|
image: php:8.3
|
||||||
|
@ -296,13 +394,13 @@ jobs:
|
||||||
|
|
||||||
- name: Build project
|
- name: Build project
|
||||||
run: |
|
run: |
|
||||||
ncc build --config debug_executable --build-source --log-level debug
|
ncc build --config debug-compressed-executable --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-compressed-executable
|
||||||
path: build/debug/ConfigLib
|
path: build/debug/debug_compressed_executable
|
||||||
|
|
||||||
|
|
||||||
# Checking for phpunit.xml
|
# Checking for phpunit.xml
|
||||||
|
@ -373,7 +471,7 @@ jobs:
|
||||||
path: docs.zip
|
path: docs.zip
|
||||||
|
|
||||||
test:
|
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
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
image: php:8.3
|
image: php:8.3
|
||||||
|
@ -467,7 +565,7 @@ jobs:
|
||||||
|
|
||||||
|
|
||||||
release-artifacts:
|
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
|
permissions: write-all
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
|
@ -502,6 +600,30 @@ 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:
|
||||||
|
@ -526,27 +648,27 @@ jobs:
|
||||||
debug-executable/*
|
debug-executable/*
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
- name: Download release_executable artifact
|
- name: Download release-compressed-executable artifact
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: release_executable
|
name: release-compressed-executable
|
||||||
path: release_executable
|
path: release-compressed-executable
|
||||||
- name: Upload release_executable artifact to release
|
- name: Upload release-compressed-executable artifact to release
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
with:
|
with:
|
||||||
files: |
|
files: |
|
||||||
release_executable/*
|
release-compressed-executable/*
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
- name: Download debug_executable artifact
|
- name: Download debug-compressed-executable artifact
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: debug_executable
|
name: debug-compressed-executable
|
||||||
path: debug_executable
|
path: debug-compressed-executable
|
||||||
- name: Upload debug_executable artifact to release
|
- name: Upload debug-compressed-executable artifact to release
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
with:
|
with:
|
||||||
files: |
|
files: |
|
||||||
debug_executable/*
|
debug-compressed-executable/*
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
14
.idea/php.xml
generated
14
.idea/php.xml
generated
|
@ -12,11 +12,14 @@
|
||||||
<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.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/com.symfony.yaml=v7.1.5" />
|
||||||
<path value="/var/ncc/packages/net.nosial.loglib=2.0.4" />
|
<path value="/var/ncc/packages/com.symfony.filesystem=v7.1.5" />
|
||||||
<path value="/var/ncc/packages/com.symfony.polyfill_mbstring=v1.31.0" />
|
|
||||||
<path value="/var/ncc/packages/com.symfony.polyfill_ctype=v1.31.0" />
|
<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/ncc" />
|
||||||
<path value="/usr/share/php" />
|
<path value="/usr/share/php" />
|
||||||
</include_path>
|
</include_path>
|
||||||
|
@ -25,9 +28,12 @@
|
||||||
<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="$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>
|
</phpunit_settings>
|
||||||
</component>
|
</component>
|
||||||
<component name="PsalmOptionsConfiguration">
|
<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/),
|
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
|
||||||
|
|
||||||
### Fixed
|
### 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
|
## [1.1.3] - 2024-10-13
|
||||||
|
@ -50,11 +18,8 @@ This update introduces a minor bug fix
|
||||||
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
|
||||||
|
|
31
Makefile
31
Makefile
|
@ -1,33 +1,20 @@
|
||||||
# Variables
|
# Variables
|
||||||
DEFAULT_CONFIGURATION ?= release
|
CONFIG ?= release
|
||||||
LOG_LEVEL = debug
|
LOG_LEVEL = debug
|
||||||
|
OUTDIR = build/$(CONFIG)
|
||||||
|
PACKAGE = $(OUTDIR)/net.nosial.configlib.ncc
|
||||||
|
|
||||||
# Default Target
|
# Default Target
|
||||||
all: release debug release-executable debug-executable release_executable debug_executable
|
all: build
|
||||||
|
|
||||||
# Build Steps
|
# Build Steps
|
||||||
release:
|
build:
|
||||||
ncc build --config=release --log-level $(LOG_LEVEL)
|
ncc build --config=$(CONFIG) --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:
|
||||||
install: release
|
ncc package install --package=$(PACKAGE) --skip-dependencies --build-source --reinstall -y --log-level $(LOG_LEVEL)
|
||||||
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 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.
|
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
24
main
|
@ -1,24 +1,6 @@
|
||||||
<?php
|
<?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');
|
require('ncc');
|
||||||
\ncc\Classes\Runtime::import('net.nosial.configlib', 'latest');
|
import('net.nosial.configlib', 'latest');
|
||||||
exit(\ConfigLib\Program::main($argv));
|
|
||||||
|
\ConfigLib\Program::main();
|
53
project.json
53
project.json
|
@ -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.7",
|
"version": "1.1.4",
|
||||||
"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_policy",
|
"main": "main",
|
||||||
"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/optslib=latest@github"
|
"source": "nosial/libs.opts=latest@n64"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "net.nosial.loglib2",
|
"name": "net.nosial.loglib",
|
||||||
"version": "latest",
|
"version": "latest",
|
||||||
"source": "nosial/loglib2=latest@github"
|
"source": "nosial/libs.log=latest@n64"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "com.symfony.filesystem",
|
"name": "com.symfony.filesystem",
|
||||||
|
@ -75,6 +75,25 @@
|
||||||
"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",
|
||||||
|
@ -92,26 +111,28 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "release_executable",
|
"name": "release-compressed-executable",
|
||||||
"build_type": "executable",
|
"build_type": "executable",
|
||||||
"output": "build/release/%ASSEMBLY.NAME%",
|
"output": "build/release/release_compressed_executable",
|
||||||
"options": {
|
"options": {
|
||||||
"ncc_configuration": "release"
|
"ncc_configuration": "release-compressed"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "debug_executable",
|
"name": "debug-compressed-executable",
|
||||||
"build_type": "executable",
|
"build_type": "executable",
|
||||||
"output": "build/debug/%ASSEMBLY.NAME%",
|
"output": "build/debug/debug_compressed_executable",
|
||||||
"options": {
|
"options": {
|
||||||
"ncc_configuration": "debug"
|
"ncc_configuration": "debug-compressed"
|
||||||
},
|
|
||||||
"define_constants": {
|
|
||||||
"DEBUG": "1"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"installer": {
|
||||||
|
"post_install": [
|
||||||
|
"setup"
|
||||||
|
]
|
||||||
|
},
|
||||||
"execution_policies": [
|
"execution_policies": [
|
||||||
{
|
{
|
||||||
"name": "main",
|
"name": "main",
|
||||||
|
@ -126,7 +147,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "main_policy",
|
"name": "setup",
|
||||||
"runner": "php",
|
"runner": "php",
|
||||||
"execute": {
|
"execute": {
|
||||||
"working_directory": "%CWD%",
|
"working_directory": "%CWD%",
|
||||||
|
@ -134,7 +155,7 @@
|
||||||
"tty": true,
|
"tty": true,
|
||||||
"timeout": null,
|
"timeout": null,
|
||||||
"idle_timeout": null,
|
"idle_timeout": null,
|
||||||
"target": "main"
|
"target": "setup"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,61 +1,57 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/** @noinspection PhpMissingFieldTypeInspection */
|
||||||
|
|
||||||
namespace ConfigLib;
|
namespace ConfigLib;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use LogLib2\Logger;
|
use LogLib\Log;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
|
||||||
class Configuration
|
class Configuration
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* The logger of the class
|
|
||||||
* @var Logger
|
|
||||||
*/
|
|
||||||
private Logger $logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the configuration
|
* The name of the configuration
|
||||||
* @var string|array
|
*
|
||||||
|
* @var string
|
||||||
*/
|
*/
|
||||||
private string|array $name;
|
private $name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The path to the configuration file
|
* The path to the configuration file
|
||||||
* @var string|null
|
*
|
||||||
|
* @var string
|
||||||
*/
|
*/
|
||||||
private ?string $path;
|
private $path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The configuration data
|
* The configuration data
|
||||||
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private array $configuration;
|
private $configuration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates if the current instance is modified
|
* Indicates if the current instance is modified
|
||||||
|
*
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
private bool $modified;
|
private $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', ?string $path=null)
|
public function __construct(string $name='default')
|
||||||
{
|
{
|
||||||
$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)));
|
|
||||||
$this->path = null;
|
|
||||||
|
|
||||||
|
$env = getenv(sprintf("CONFIGLIB_%s", strtoupper($name)));
|
||||||
if($env !== false)
|
if($env !== false)
|
||||||
{
|
{
|
||||||
if(file_exists($env))
|
if(file_exists($env))
|
||||||
|
@ -64,84 +60,66 @@
|
||||||
}
|
}
|
||||||
else
|
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)))
|
$this->path = $globalDir . DIRECTORY_SEPARATOR . $name . '.conf';
|
||||||
{
|
|
||||||
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 (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
|
||||||
|
|
||||||
// If the CONFIGLIB_PATH environment variable is set, use it as the configuration path
|
|
||||||
if(getenv('CONFIGLIB_PATH'))
|
|
||||||
{
|
{
|
||||||
$configDir = getenv('CONFIGLIB_PATH');
|
$configDir = getenv('APPDATA') ?: getenv('LOCALAPPDATA');
|
||||||
|
|
||||||
|
if (!$configDir)
|
||||||
|
{
|
||||||
|
// Fallback to system temporary directory
|
||||||
|
$configDir = sys_get_temp_dir();
|
||||||
|
}
|
||||||
|
|
||||||
|
$configDir .= DIRECTORY_SEPARATOR . 'ConfigLib';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
|
$homeDir = getenv('HOME') ?: '';
|
||||||
|
$configDirs = [];
|
||||||
|
|
||||||
|
if ($homeDir)
|
||||||
{
|
{
|
||||||
$configDir = getenv('APPDATA') ?: getenv('LOCALAPPDATA');
|
$configDirs[] = $homeDir . DIRECTORY_SEPARATOR . '.configlib';
|
||||||
|
$configDirs[] = $homeDir . DIRECTORY_SEPARATOR . '.config' . DIRECTORY_SEPARATOR . 'configlib';
|
||||||
if (!$configDir)
|
|
||||||
{
|
|
||||||
// Fallback to system temporary directory
|
|
||||||
$configDir = sys_get_temp_dir();
|
|
||||||
}
|
|
||||||
|
|
||||||
$configDir .= DIRECTORY_SEPARATOR . 'ConfigLib';
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
$configDirs[] = '/etc/configlib';
|
||||||
|
$configDirs[] = '/var/lib/configlib';
|
||||||
|
|
||||||
|
$configDir = null;
|
||||||
|
|
||||||
|
// Iterate over the list of directories and select the first one that can be created or written to
|
||||||
|
foreach ($configDirs as $dir)
|
||||||
{
|
{
|
||||||
$homeDir = getenv('HOME') ?: '';
|
if (file_exists($dir) && is_writable($dir))
|
||||||
$configDirs = [];
|
|
||||||
|
|
||||||
if ($homeDir)
|
|
||||||
{
|
{
|
||||||
$configDirs[] = $homeDir . DIRECTORY_SEPARATOR . '.configlib';
|
$configDir = $dir;
|
||||||
$configDirs[] = $homeDir . DIRECTORY_SEPARATOR . '.config' . DIRECTORY_SEPARATOR . 'configlib';
|
break;
|
||||||
}
|
}
|
||||||
|
elseif (!file_exists($dir) && mkdir($dir, 0755, true))
|
||||||
$configDirs[] = '/etc/configlib';
|
|
||||||
$configDirs[] = '/var/lib/configlib';
|
|
||||||
|
|
||||||
$configDir = null;
|
|
||||||
|
|
||||||
// Iterate over the list of directories and select the first one that can be created or written to
|
|
||||||
foreach ($configDirs as $dir)
|
|
||||||
{
|
{
|
||||||
if (file_exists($dir) && is_writable($dir))
|
$configDir = $dir;
|
||||||
{
|
break;
|
||||||
$configDir = $dir;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
elseif (!file_exists($dir) && mkdir($dir, 0755, true))
|
|
||||||
{
|
|
||||||
$configDir = $dir;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!$configDir)
|
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';
|
$configDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'configlib';
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +149,7 @@
|
||||||
}
|
}
|
||||||
catch(Exception $e)
|
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);
|
throw new RuntimeException(sprintf('Unable to load configuration "%s"', $this->name), $e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,7 +171,6 @@
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,7 +340,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->modified = false;
|
$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->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)
|
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->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';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue