Compare commits
144 commits
Author | SHA1 | Date | |
---|---|---|---|
88ec33ff1a | |||
bf71326090 | |||
![]() |
936485dde7 | ||
![]() |
6966fd39d0 | ||
![]() |
09b2e88e1c | ||
![]() |
561064261c | ||
![]() |
faad3e69de | ||
![]() |
9e97a6d414 | ||
![]() |
015f13bf12 | ||
![]() |
514d527923 | ||
![]() |
489196267e | ||
![]() |
994d4092fc | ||
![]() |
579813315b | ||
![]() |
28d67deaa8 | ||
![]() |
3285bec11f | ||
![]() |
37a8918198 | ||
![]() |
8d6a2c33bd | ||
![]() |
6b446ce54a | ||
e704df03df | |||
a7395e4663 | |||
d309385993 | |||
655eca1695 | |||
1bcd09cc1e | |||
dea75c9eeb | |||
5b6be331f0 | |||
d56d940da2 | |||
1f9c5576e0 | |||
876a33ffc7 | |||
b9679d168f | |||
4b05581bb6 | |||
742be22eac | |||
aa6dca302f | |||
b19eeb6720 | |||
![]() |
ff2296c786 | ||
![]() |
2c05ae8b3c | ||
![]() |
beb133dc75 | ||
![]() |
6eb1f68f98 | ||
![]() |
26d2b0acd8 | ||
![]() |
cfbbed5c4a | ||
![]() |
230f865093 | ||
e4c494ef58 | |||
376e334cb5 | |||
3c89ebe4a1 | |||
539a180f76 | |||
![]() |
6660af9fda | ||
![]() |
02d1cdc8d0 | ||
![]() |
c51ee499be | ||
![]() |
a223dabc28 | ||
![]() |
58cc299536 | ||
![]() |
93db7fcd2c | ||
![]() |
ed6d1f191c | ||
![]() |
389b38283e | ||
![]() |
0caabd860d | ||
![]() |
0f6980bc8a | ||
![]() |
14dfb45e98 | ||
![]() |
58ddce6918 | ||
![]() |
12acabe9b1 | ||
![]() |
ad4805643b | ||
![]() |
2d7c840468 | ||
![]() |
f9d96524e9 | ||
![]() |
76ca3f5290 | ||
![]() |
0d823c88e7 | ||
![]() |
e96695a5d8 | ||
65125c496a | |||
cd4ea10fd6 | |||
bb4a93a364 | |||
2c33fa2f49 | |||
8dc2d1c70d | |||
56f57f89de | |||
19935179a0 | |||
1eae8df0e3 | |||
371c486c4f | |||
7411563758 | |||
84ad9a9fb3 | |||
870a8d6b4e | |||
ec741fd3ef | |||
3cf70a1f2b | |||
a19f372150 | |||
af03b4ffda | |||
94ba9a93df | |||
2fd12137ae | |||
b568f75d0b | |||
d75fbd72d2 | |||
![]() |
b8e83d31bc | ||
![]() |
489df9f79a | ||
![]() |
2f41614d20 | ||
![]() |
698e2cb334 | ||
![]() |
b5874371b1 | ||
![]() |
0c837c6b54 | ||
![]() |
386e137547 | ||
![]() |
e3b2a3cf9a | ||
![]() |
9f98b4c9b8 | ||
![]() |
1b94a273b7 | ||
![]() |
649d04d8aa | ||
![]() |
6cdc2336cd | ||
![]() |
b34005af1b | ||
![]() |
a259f45684 | ||
![]() |
4299096a09 | ||
![]() |
93efe5741a | ||
![]() |
0f5036742f | ||
![]() |
20441809cc | ||
![]() |
5a24645f09 | ||
![]() |
6abf687e93 | ||
![]() |
a3c9fe41f3 | ||
![]() |
8042e50863 | ||
![]() |
276aec0df6 | ||
![]() |
02d6c75bf3 | ||
![]() |
b5c7d08e57 | ||
![]() |
6420b9bfed | ||
![]() |
bdf6021953 | ||
![]() |
287d86e9e9 | ||
![]() |
1c3988206e | ||
![]() |
770e327f1a | ||
![]() |
64fb1a4bfe | ||
![]() |
25aba53494 | ||
![]() |
fa8a8ea84c | ||
![]() |
b651079fb5 | ||
![]() |
2e21dbc2cd | ||
![]() |
385000907e | ||
![]() |
414fd0a781 | ||
![]() |
311132e765 | ||
![]() |
ad0c7f3e06 | ||
![]() |
5f52e7dd9e | ||
![]() |
45b7879186 | ||
![]() |
9bc1f86e25 | ||
![]() |
ffc91de77e | ||
![]() |
17f95d619f | ||
![]() |
6a4e3de7a3 | ||
![]() |
cbd4b459bb | ||
![]() |
813e2c4594 | ||
![]() |
41ad1ae694 | ||
![]() |
93b06e8b00 | ||
![]() |
97404dc382 | ||
![]() |
fbff562545 | ||
![]() |
a1a6ae01a3 | ||
![]() |
8c6313c687 | ||
![]() |
a56622b82a | ||
![]() |
4224342369 | ||
![]() |
65fee96352 | ||
![]() |
06b05c350a | ||
![]() |
d44020aacf | ||
![]() |
b405190389 | ||
ec3a7834c6 | |||
85f0aab16b |
20 changed files with 1196 additions and 219 deletions
552
.github/workflows/ncc_workflow.yml
vendored
Normal file
552
.github/workflows/ncc_workflow.yml
vendored
Normal file
|
@ -0,0 +1,552 @@
|
||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- '**'
|
||||||
|
release:
|
||||||
|
types: [created]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
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 --build-source --log-level debug
|
||||||
|
|
||||||
|
- name: Upload build artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: release
|
||||||
|
path: build/release/net.nosial.configlib.ncc
|
||||||
|
debug:
|
||||||
|
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 --build-source --log-level debug
|
||||||
|
|
||||||
|
- name: Upload build artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: debug
|
||||||
|
path: build/debug/net.nosial.configlib.ncc
|
||||||
|
release-executable:
|
||||||
|
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-executable --build-source --log-level debug
|
||||||
|
|
||||||
|
- name: Upload build artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: release-executable
|
||||||
|
path: build/release/release_executable_gz
|
||||||
|
debug-executable:
|
||||||
|
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-executable --build-source --log-level debug
|
||||||
|
|
||||||
|
- name: Upload build artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: debug-executable
|
||||||
|
path: build/debug/debug_executable_gz
|
||||||
|
release_executable:
|
||||||
|
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_executable --build-source --log-level debug
|
||||||
|
|
||||||
|
- name: Upload build artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: release_executable
|
||||||
|
path: build/release/ConfigLib
|
||||||
|
debug_executable:
|
||||||
|
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_executable --build-source --log-level debug
|
||||||
|
|
||||||
|
- name: Upload build artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: debug_executable
|
||||||
|
path: build/debug/ConfigLib
|
||||||
|
|
||||||
|
|
||||||
|
# Checking for phpunit.xml
|
||||||
|
check-phpunit:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
phpunit-exists: ${{ steps.check.outputs.phpunit-exists }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Check for phpunit.xml
|
||||||
|
id: check
|
||||||
|
run: |
|
||||||
|
if [ -f phpunit.xml ]; then
|
||||||
|
echo "phpunit-exists=true" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "phpunit-exists=false" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
# Checking for phpdoc.dist.xml
|
||||||
|
check-phpdoc:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
phpdoc-exists: ${{ steps.check.outputs.phpdoc-exists }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Check for phpdoc.dist.xml
|
||||||
|
id: check
|
||||||
|
run: |
|
||||||
|
if [ -f phpdoc.dist.xml ]; then
|
||||||
|
echo "phpdoc-exists=true" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "phpdoc-exists=false" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
generate-phpdoc:
|
||||||
|
needs: [release, check-phpdoc]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: php:8.3
|
||||||
|
if: needs.check-phpdoc.outputs.phpdoc-exists == 'true'
|
||||||
|
|
||||||
|
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: Download PHPDocumentor
|
||||||
|
run: |
|
||||||
|
wget https://phpdoc.org/phpDocumentor.phar
|
||||||
|
chmod +x phpDocumentor.phar
|
||||||
|
|
||||||
|
- name: Generate PHPDoc
|
||||||
|
run: |
|
||||||
|
php phpDocumentor.phar -d src -t docs
|
||||||
|
|
||||||
|
- name: Archive PHPDoc
|
||||||
|
run: |
|
||||||
|
zip -r docs.zip docs
|
||||||
|
|
||||||
|
- name: Upload PHPDoc
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: documentation
|
||||||
|
path: docs.zip
|
||||||
|
|
||||||
|
test:
|
||||||
|
needs: [release, debug, release-executable, debug-executable, release_executable, debug_executable, check-phpunit]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: php:8.3
|
||||||
|
if: needs.check-phpunit.outputs.phpunit-exists == 'true'
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Download build artifacts
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: release
|
||||||
|
path: release
|
||||||
|
|
||||||
|
- 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="release/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 --log-junit reports/junit.xml --log-teamcity reports/teamcity --testdox-html reports/testdox.html --testdox-text reports/testdox.txt
|
||||||
|
|
||||||
|
- name: Upload test reports
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: reports
|
||||||
|
path: reports
|
||||||
|
|
||||||
|
|
||||||
|
release-documentation:
|
||||||
|
needs: generate-phpdoc
|
||||||
|
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 documentation artifact
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: documentation
|
||||||
|
path: documentation
|
||||||
|
|
||||||
|
- name: Upload documentation artifact
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
files: |
|
||||||
|
documentation/*
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
|
||||||
|
release-artifacts:
|
||||||
|
needs: [release, debug, release-executable, debug-executable, release_executable, debug_executable]
|
||||||
|
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 release artifact
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: release
|
||||||
|
path: release
|
||||||
|
- name: Upload release artifact to release
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
files: |
|
||||||
|
release/*
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Download debug artifact
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: debug
|
||||||
|
path: debug
|
||||||
|
- name: Upload debug artifact to release
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
files: |
|
||||||
|
debug/*
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Download release-executable artifact
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: release-executable
|
||||||
|
path: release-executable
|
||||||
|
- name: Upload release-executable artifact to release
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
files: |
|
||||||
|
release-executable/*
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Download debug-executable artifact
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: debug-executable
|
||||||
|
path: debug-executable
|
||||||
|
- name: Upload debug-executable artifact to release
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
files: |
|
||||||
|
debug-executable/*
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Download release_executable artifact
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: release_executable
|
||||||
|
path: release_executable
|
||||||
|
- name: Upload release_executable artifact to release
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
files: |
|
||||||
|
release_executable/*
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Download debug_executable artifact
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: debug_executable
|
||||||
|
path: debug_executable
|
||||||
|
- name: Upload debug_executable artifact to release
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
files: |
|
||||||
|
debug_executable/*
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1 +1,5 @@
|
||||||
build/
|
build/
|
||||||
|
/.idea/php-test-framework.xml
|
||||||
|
/.idea/gbrowser_project.xml
|
||||||
|
/.phpunit.result.cache
|
||||||
|
/reports
|
|
@ -1,9 +1,12 @@
|
||||||
image: php:8.1
|
image: php:8.3
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
# Install some stuff that the image doesn't come with
|
# Install some stuff that the image doesn't come with
|
||||||
- apt update -yqq
|
- apt update -yqq
|
||||||
- apt install git libpq-dev libzip-dev zip make wget gnupg -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
|
||||||
|
|
||||||
# Install phive
|
# Install phive
|
||||||
- wget -O phive.phar https://phar.io/releases/phive.phar
|
- wget -O phive.phar https://phar.io/releases/phive.phar
|
||||||
|
@ -20,10 +23,17 @@ before_script:
|
||||||
- git clone https://git.n64.cc/nosial/ncc.git
|
- git clone https://git.n64.cc/nosial/ncc.git
|
||||||
- cd ncc
|
- cd ncc
|
||||||
- make redist
|
- make redist
|
||||||
- php build/src/INSTALL --auto --install-composer
|
- 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 --install-composer
|
||||||
- cd .. && rm -rf ncc
|
- cd .. && rm -rf ncc
|
||||||
|
|
||||||
build:
|
build:
|
||||||
|
stage: build
|
||||||
script:
|
script:
|
||||||
- ncc build --config release --log-level debug
|
- ncc build --config release --log-level debug
|
||||||
artifacts:
|
artifacts:
|
||||||
|
@ -31,6 +41,15 @@ build:
|
||||||
- build/
|
- build/
|
||||||
rules:
|
rules:
|
||||||
- if: $CI_COMMIT_BRANCH
|
- if: $CI_COMMIT_BRANCH
|
||||||
|
test:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- ncc package install --package="build/release/net.nosial.configlib.ncc" --reinstall -y --log-level debug
|
||||||
|
|
||||||
|
- wget https://phar.phpunit.de/phpunit-11.3.phar
|
||||||
|
- php phpunit-11.3.phar --configuration phpunit.xml
|
||||||
|
rules:
|
||||||
|
- if: $CI_COMMIT_BRANCH
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: deploy
|
stage: deploy
|
||||||
|
|
1
.idea/ConfigLib.iml
generated
1
.idea/ConfigLib.iml
generated
|
@ -5,6 +5,7 @@
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/reports" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
|
20
.idea/php.xml
generated
20
.idea/php.xml
generated
|
@ -11,19 +11,25 @@
|
||||||
</component>
|
</component>
|
||||||
<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.loglib2=1.0.2" />
|
||||||
|
<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.polyfill_ctype=v1.31.0" />
|
||||||
|
<path value="/usr/share/ncc" />
|
||||||
<path value="/usr/share/php" />
|
<path value="/usr/share/php" />
|
||||||
<path value="/etc/ncc" />
|
|
||||||
<path value="/var/ncc/packages/net.nosial.optslib=1.0.0" />
|
|
||||||
<path value="/var/ncc/packages/net.nosial.loglib=1.0.1" />
|
|
||||||
<path value="/var/ncc/packages/com.symfony.yaml=6.2.10" />
|
|
||||||
<path value="/var/ncc/packages/com.symfony.filesystem=6.2.10" />
|
|
||||||
<path value="/var/ncc/packages/com.symfony.process=6.2.10" />
|
|
||||||
</include_path>
|
</include_path>
|
||||||
</component>
|
</component>
|
||||||
<component name="PhpProjectSharedConfiguration" php_language_level="8.2" />
|
<component name="PhpProjectSharedConfiguration" php_language_level="8.3" />
|
||||||
<component name="PhpStanOptionsConfiguration">
|
<component name="PhpStanOptionsConfiguration">
|
||||||
<option name="transferred" value="true" />
|
<option name="transferred" value="true" />
|
||||||
</component>
|
</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" />
|
||||||
|
</phpunit_settings>
|
||||||
|
</component>
|
||||||
<component name="PsalmOptionsConfiguration">
|
<component name="PsalmOptionsConfiguration">
|
||||||
<option name="transferred" value="true" />
|
<option name="transferred" value="true" />
|
||||||
</component>
|
</component>
|
||||||
|
|
83
CHANGELOG.md
83
CHANGELOG.md
|
@ -5,6 +5,89 @@ 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
|
||||||
|
|
||||||
|
This update introduces a minor bug fix
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Fixed regex pattern for configuration properties being considered invalid when they contain an underscore.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## [1.1.3] - 2024-10-13
|
||||||
|
|
||||||
|
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
|
||||||
|
execution unit that will be executed post-installation to ensure that the configuration file is accessible by the user
|
||||||
|
account running the application.
|
||||||
|
|
||||||
|
|
||||||
|
## [1.1.1] - 2024-09-26
|
||||||
|
|
||||||
|
This update introduces a minor bug fix
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Fixed issue where keys containing underscores are considered to be invalid
|
||||||
|
|
||||||
|
|
||||||
|
## [1.1.0] - 2024-09-23
|
||||||
|
|
||||||
|
This update introduces changes for PHP 8.3 & NCC 2.1.0+ compatibility
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Added PhpUnit tests for the library
|
||||||
|
- Added new option `--path` to the CLI interface to display the path to the configuration file
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Updated the codebase to be compatible with PHP 8.3
|
||||||
|
- Updated the codebase to be compatible with NCC 2.1.0+
|
||||||
|
- Updated Makefile
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Fixed regex patterns to be more robust
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## [1.0.4] - 2023-08-12
|
## [1.0.4] - 2023-08-12
|
||||||
|
|
||||||
This update introduces minor improvements
|
This update introduces minor improvements
|
||||||
|
|
33
Makefile
33
Makefile
|
@ -1,8 +1,33 @@
|
||||||
build:
|
# Variables
|
||||||
ncc build --config="release" --log-level debug
|
DEFAULT_CONFIGURATION ?= release
|
||||||
|
LOG_LEVEL = debug
|
||||||
|
|
||||||
install:
|
# Default Target
|
||||||
sudo ncc package install --package="build/release/net.nosial.configlib.ncc" --skip-dependencies --reinstall -y --log-level debug
|
all: release debug release-executable debug-executable release_executable debug_executable
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
|
||||||
|
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 install test clean release debug release-executable debug-executable release_executable debug_executable
|
15
README.md
15
README.md
|
@ -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)
|
||||||
|
|
3
bootstrap.php
Normal file
3
bootstrap.php
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<?php
|
||||||
|
require 'ncc';
|
||||||
|
import('net.nosial.configlib');
|
24
main
24
main
|
@ -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));
|
15
phpdoc.dist.xml
Normal file
15
phpdoc.dist.xml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<phpdocumentor configVersion="3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://www.phpdoc.org" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/phpDocumentor/phpDocumentor/master/data/xsd/phpdoc.xsd">
|
||||||
|
<paths>
|
||||||
|
<output>build/docs</output>
|
||||||
|
<cache>build/cache</cache>
|
||||||
|
</paths>
|
||||||
|
<version number="latest">
|
||||||
|
<api>
|
||||||
|
<source dsn=".">
|
||||||
|
<path>src/ConfigLib</path>
|
||||||
|
</source>
|
||||||
|
<default-package-name>ConfigLib</default-package-name>
|
||||||
|
</api>
|
||||||
|
</version>
|
||||||
|
</phpdocumentor>
|
11
phpunit.xml
Normal file
11
phpunit.xml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<phpunit bootstrap="bootstrap.php">
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="ConfigLib Test Suite">
|
||||||
|
<directory>tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
<php>
|
||||||
|
<ini name="error_reporting" value="-1"/>
|
||||||
|
<server name="KERNEL_DIR" value="app/"/>
|
||||||
|
</php>
|
||||||
|
</phpunit>
|
172
project.json
172
project.json
|
@ -5,6 +5,9 @@
|
||||||
"minimum_version": "8.0",
|
"minimum_version": "8.0",
|
||||||
"maximum_version": "8.2"
|
"maximum_version": "8.2"
|
||||||
},
|
},
|
||||||
|
"options": {
|
||||||
|
"create_symlink": true
|
||||||
|
},
|
||||||
"update_source": {
|
"update_source": {
|
||||||
"source": "nosial/libs.config@n64",
|
"source": "nosial/libs.config@n64",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -13,75 +16,126 @@
|
||||||
"host": "git.n64.cc",
|
"host": "git.n64.cc",
|
||||||
"ssl": true
|
"ssl": true
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"options": {
|
|
||||||
"create_symlink": true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"assembly": {
|
||||||
|
"name": "ConfigLib",
|
||||||
|
"package": "net.nosial.configlib",
|
||||||
|
"description": "ConfigLib is a library for reading and writing configuration files via the NCC Runtime API",
|
||||||
|
"company": "Nosial",
|
||||||
|
"copyright": "Copyright (c) 2022-2023 Nosial",
|
||||||
|
"version": "1.1.7",
|
||||||
|
"uuid": "9347259e-8e4d-11ed-85a7-fd07cf28ef35"
|
||||||
|
},
|
||||||
|
"build": {
|
||||||
|
"source_path": "src",
|
||||||
|
"default_configuration": "release",
|
||||||
|
"main": "main_policy",
|
||||||
|
"define_constants": {
|
||||||
|
"VERSION": "%ASSEMBLY.VERSION%"
|
||||||
|
},
|
||||||
|
"dependencies": [
|
||||||
|
{
|
||||||
|
"name": "net.nosial.optslib",
|
||||||
|
"version": "latest",
|
||||||
|
"source": "nosial/optslib=latest@github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "net.nosial.loglib2",
|
||||||
|
"version": "latest",
|
||||||
|
"source": "nosial/loglib2=latest@github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "com.symfony.filesystem",
|
||||||
|
"version": "latest",
|
||||||
|
"source": "symfony/filesystem=latest@packagist"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "com.symfony.yaml",
|
||||||
|
"version": "latest",
|
||||||
|
"source": "symfony/yaml=latest@packagist"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "com.symfony.process",
|
||||||
|
"version": "latest",
|
||||||
|
"source": "symfony/process=latest@packagist"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "release",
|
||||||
|
"build_type": "ncc",
|
||||||
|
"output": "build/release/%ASSEMBLY.PACKAGE%.ncc"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "debug",
|
||||||
|
"build_type": "ncc",
|
||||||
|
"output": "build/debug/%ASSEMBLY.PACKAGE%.ncc",
|
||||||
|
"define_constants": {
|
||||||
|
"DEBUG": "1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "release-executable",
|
||||||
|
"build_type": "executable",
|
||||||
|
"output": "build/release/release_executable_gz",
|
||||||
|
"options": {
|
||||||
|
"ncc_configuration": "release"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "debug-executable",
|
||||||
|
"build_type": "executable",
|
||||||
|
"output": "build/debug/debug_executable_gz",
|
||||||
|
"options": {
|
||||||
|
"ncc_configuration": "debug"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "release_executable",
|
||||||
|
"build_type": "executable",
|
||||||
|
"output": "build/release/%ASSEMBLY.NAME%",
|
||||||
|
"options": {
|
||||||
|
"ncc_configuration": "release"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "debug_executable",
|
||||||
|
"build_type": "executable",
|
||||||
|
"output": "build/debug/%ASSEMBLY.NAME%",
|
||||||
|
"options": {
|
||||||
|
"ncc_configuration": "debug"
|
||||||
|
},
|
||||||
|
"define_constants": {
|
||||||
|
"DEBUG": "1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"execution_policies": [
|
"execution_policies": [
|
||||||
{
|
{
|
||||||
"name": "main",
|
"name": "main",
|
||||||
"runner": "php",
|
"runner": "php",
|
||||||
"execute": {
|
"execute": {
|
||||||
"target": "main",
|
|
||||||
"working_directory": "%CWD%",
|
"working_directory": "%CWD%",
|
||||||
"tty": true
|
"silent": false,
|
||||||
|
"tty": true,
|
||||||
|
"timeout": null,
|
||||||
|
"idle_timeout": null,
|
||||||
|
"target": "main"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "main_policy",
|
||||||
|
"runner": "php",
|
||||||
|
"execute": {
|
||||||
|
"working_directory": "%CWD%",
|
||||||
|
"silent": false,
|
||||||
|
"tty": true,
|
||||||
|
"timeout": null,
|
||||||
|
"idle_timeout": null,
|
||||||
|
"target": "main"
|
||||||
}
|
}
|
||||||
],
|
|
||||||
"assembly": {
|
|
||||||
"name": "ConfigLib",
|
|
||||||
"package": "net.nosial.configlib",
|
|
||||||
"company": "Nosial",
|
|
||||||
"copyright": "Copyright (c) 2022-2023 Nosial",
|
|
||||||
"description": "ConfigLib is a library for reading and writing configuration files via the NCC Runtime API",
|
|
||||||
"version": "1.0.4",
|
|
||||||
"uuid": "9347259e-8e4d-11ed-85a7-fd07cf28ef35"
|
|
||||||
},
|
|
||||||
"build": {
|
|
||||||
"source_path": "src",
|
|
||||||
"default_configuration": "release",
|
|
||||||
"main": "main",
|
|
||||||
"define_constants": {
|
|
||||||
"version": "%ASSEMBLY.VERSION%"
|
|
||||||
},
|
|
||||||
"dependencies": [
|
|
||||||
{
|
|
||||||
"name": "net.nosial.optslib",
|
|
||||||
"version": "latest",
|
|
||||||
"source_type": "remote",
|
|
||||||
"source": "nosial/libs.opts=latest@n64"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "net.nosial.loglib",
|
|
||||||
"version": "latest",
|
|
||||||
"source_type": "remote",
|
|
||||||
"source": "nosial/libs.log=latest@n64"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.symfony.filesystem",
|
|
||||||
"version": "latest",
|
|
||||||
"source_type": "remote",
|
|
||||||
"source": "symfony/filesystem=latest@composer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.symfony.yaml",
|
|
||||||
"version": "latest",
|
|
||||||
"source_type": "remote",
|
|
||||||
"source": "symfony/yaml=latest@composer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.symfony.process",
|
|
||||||
"version": "latest",
|
|
||||||
"source_type": "remote",
|
|
||||||
"source": "symfony/process=latest@composer"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "release",
|
|
||||||
"output_path": "build/release"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
14
setup
Normal file
14
setup
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$global_directory = $path = DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . 'configlib';
|
||||||
|
|
||||||
|
//try creating the directory if it doesn't exist
|
||||||
|
if(!file_exists($global_directory))
|
||||||
|
{
|
||||||
|
if(!mkdir($global_directory, 0777, true))
|
||||||
|
{
|
||||||
|
exit('Failed to create global directory');
|
||||||
|
}
|
||||||
|
|
||||||
|
chmod($global_directory, 0777);
|
||||||
|
}
|
|
@ -1,12 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/** @noinspection PhpMissingFieldTypeInspection */
|
|
||||||
|
|
||||||
namespace ConfigLib;
|
namespace ConfigLib;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use LogLib\Log;
|
use LogLib2\Logger;
|
||||||
use ncc\Runtime;
|
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
@ -14,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))
|
||||||
|
@ -61,21 +64,97 @@
|
||||||
}
|
}
|
||||||
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($path !== null)
|
||||||
|
{
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
// Figure out the path to the configuration file
|
$filePath = $name . '.conf';
|
||||||
try
|
|
||||||
|
// If the CONFIGLIB_PATH environment variable is set, use it as the configuration path
|
||||||
|
if(getenv('CONFIGLIB_PATH'))
|
||||||
{
|
{
|
||||||
$this->path = Runtime::getDataPath('net.nosial.configlib') . DIRECTORY_SEPARATOR . $name . '.conf';
|
$configDir = getenv('CONFIGLIB_PATH');
|
||||||
}
|
}
|
||||||
catch (Exception $e)
|
else
|
||||||
{
|
{
|
||||||
throw new RuntimeException('Unable to load package "net.nosial.configlib"', $e);
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
|
||||||
|
{
|
||||||
|
$configDir = getenv('APPDATA') ?: getenv('LOCALAPPDATA');
|
||||||
|
|
||||||
|
if (!$configDir)
|
||||||
|
{
|
||||||
|
// Fallback to system temporary directory
|
||||||
|
$configDir = sys_get_temp_dir();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$configDir .= DIRECTORY_SEPARATOR . 'ConfigLib';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$homeDir = getenv('HOME') ?: '';
|
||||||
|
$configDirs = [];
|
||||||
|
|
||||||
|
if ($homeDir)
|
||||||
|
{
|
||||||
|
$configDirs[] = $homeDir . DIRECTORY_SEPARATOR . '.configlib';
|
||||||
|
$configDirs[] = $homeDir . DIRECTORY_SEPARATOR . '.config' . DIRECTORY_SEPARATOR . 'configlib';
|
||||||
|
}
|
||||||
|
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
elseif (!file_exists($dir) && mkdir($dir, 0755, true))
|
||||||
|
{
|
||||||
|
$configDir = $dir;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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()));
|
||||||
|
$configDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'configlib';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure the directory exists
|
||||||
|
if (!file_exists($configDir))
|
||||||
|
{
|
||||||
|
if (!mkdir($configDir, 0755, true) && !is_dir($configDir))
|
||||||
|
{
|
||||||
|
throw new RuntimeException(sprintf('Directory "%s" was not created', $configDir));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->path = $configDir . DIRECTORY_SEPARATOR . $filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the name
|
// Set the name
|
||||||
|
@ -92,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,14 +184,12 @@
|
||||||
/**
|
/**
|
||||||
* Validates a key syntax (e.g. "key1.key2.key3")
|
* Validates a key syntax (e.g. "key1.key2.key3")
|
||||||
*
|
*
|
||||||
* @param string $input
|
* @param string $input The key to validate
|
||||||
* @return bool
|
* @return bool True if the key is valid, false otherwise
|
||||||
*/
|
*/
|
||||||
private static function validateKey(string $input): bool
|
private static function validateKey(string $input): bool
|
||||||
{
|
{
|
||||||
$pattern = '/^([a-zA-Z]+\.?)+$/';
|
if (preg_match('/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*$/', $input))
|
||||||
|
|
||||||
if (preg_match($pattern, $input))
|
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -120,35 +197,6 @@
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempts to convert a string to the correct type (int, float, bool, string)
|
|
||||||
*
|
|
||||||
* @param $input
|
|
||||||
* @return float|int|mixed|string
|
|
||||||
* @noinspection PhpUnusedPrivateMethodInspection
|
|
||||||
*/
|
|
||||||
private static function cast($input): mixed
|
|
||||||
{
|
|
||||||
if (is_numeric($input))
|
|
||||||
{
|
|
||||||
if(str_contains($input, '.'))
|
|
||||||
{
|
|
||||||
return (float)$input;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ctype_digit($input))
|
|
||||||
{
|
|
||||||
return (int)$input;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
elseif (in_array(strtolower($input), ['true', 'false']))
|
|
||||||
{
|
|
||||||
return filter_var($input, FILTER_VALIDATE_BOOLEAN);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (string)$input;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a value from the configuration
|
* Returns a value from the configuration
|
||||||
*
|
*
|
||||||
|
@ -179,8 +227,8 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the value at the end of the path
|
// Return the value at the end of the path, or the default if the value is null
|
||||||
return $current;
|
return $current ?? $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -193,6 +241,7 @@
|
||||||
*/
|
*/
|
||||||
public function set(string $key, mixed $value, bool $create = false): bool
|
public function set(string $key, mixed $value, bool $create = false): bool
|
||||||
{
|
{
|
||||||
|
// Validate the provided key
|
||||||
if (!self::validateKey($key))
|
if (!self::validateKey($key))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -201,27 +250,61 @@
|
||||||
$path = explode('.', $key);
|
$path = explode('.', $key);
|
||||||
$current = &$this->configuration;
|
$current = &$this->configuration;
|
||||||
|
|
||||||
// Navigate to the parent of the value to set
|
foreach ($path as $keyPart)
|
||||||
foreach ($path as $key_value)
|
|
||||||
{
|
{
|
||||||
if (is_array($current) && array_key_exists($key_value, $current))
|
if (!is_array($current))
|
||||||
{
|
{
|
||||||
$current = &$current[$key_value];
|
$current = [];
|
||||||
}
|
}
|
||||||
elseif($create)
|
|
||||||
|
if (!array_key_exists($keyPart, $current))
|
||||||
{
|
{
|
||||||
$current[$key_value] = [];
|
if ($create)
|
||||||
$current = &$current[$key_value];
|
{
|
||||||
|
$current[$keyPart] = [];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$current = &$current[$keyPart];
|
||||||
}
|
}
|
||||||
|
|
||||||
$current = $value;
|
$current = $value;
|
||||||
$this->modified = true;
|
$this->modified = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a configuration key exists
|
||||||
|
*
|
||||||
|
* @param string $key The key to check (e.g. "key1.key2.key3")
|
||||||
|
* @return bool True if the key exists, false otherwise
|
||||||
|
*/
|
||||||
|
public function exists(string $key): bool
|
||||||
|
{
|
||||||
|
// Validate the provided key
|
||||||
|
if (!self::validateKey($key))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$path = explode('.', $key);
|
||||||
|
$current = $this->configuration;
|
||||||
|
|
||||||
|
foreach ($path as $keyPart)
|
||||||
|
{
|
||||||
|
if (is_array($current) && array_key_exists($keyPart, $current))
|
||||||
|
{
|
||||||
|
$current = $current[$keyPart];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -229,9 +312,9 @@
|
||||||
/**
|
/**
|
||||||
* Sets the default value for a key if it does not exist
|
* Sets the default value for a key if it does not exist
|
||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $key The key to set (e.g. "key1.key2.key3")
|
||||||
* @param mixed $value
|
* @param mixed $value The value to set
|
||||||
* @return bool
|
* @return bool True if the value was set, false otherwise
|
||||||
*/
|
*/
|
||||||
public function setDefault(string $key, mixed $value): bool
|
public function setDefault(string $key, mixed $value): bool
|
||||||
{
|
{
|
||||||
|
@ -243,42 +326,11 @@
|
||||||
return $this->set($key, $value, true);
|
return $this->set($key, $value, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the given key exists in the configuration
|
|
||||||
*
|
|
||||||
* @param string $key
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function exists(string $key): bool
|
|
||||||
{
|
|
||||||
if(!self::validateKey($key))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$path = explode('.', $key);
|
|
||||||
$current = $this->configuration;
|
|
||||||
|
|
||||||
foreach ($path as $key_value)
|
|
||||||
{
|
|
||||||
if (is_array($current) && array_key_exists($key_value, $current))
|
|
||||||
{
|
|
||||||
$current = $current[$key_value];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the current configuration data
|
* Clears the current configuration data
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
* @noinspection PhpUnused
|
|
||||||
*/
|
*/
|
||||||
public function clear(): void
|
public function clear(): void
|
||||||
{
|
{
|
||||||
|
@ -311,15 +363,14 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
$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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the Configuration File from the disk
|
* Loads the Configuration File from the disk
|
||||||
*
|
*
|
||||||
* @param bool $force
|
* @param bool $force If true, the configuration will be reloaded even if it was not modified
|
||||||
* @return void
|
* @return void
|
||||||
* @noinspection PhpUnused
|
|
||||||
*/
|
*/
|
||||||
public function load(bool $force=false): void
|
public function load(bool $force=false): void
|
||||||
{
|
{
|
||||||
|
@ -381,6 +432,7 @@
|
||||||
{
|
{
|
||||||
$current[$key_value] = [];
|
$current[$key_value] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$current = &$current[$key_value];
|
$current = &$current[$key_value];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -393,13 +445,13 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->modified = false;
|
$this->modified = false;
|
||||||
Log::debug('net.nosial.configlib', 'Loaded configuration file: ' . $this->path);
|
$this->logger->debug('Loaded configuration file: ' . $this->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the name of the configuration
|
* Returns the name of the configuration
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string The name of the configuration
|
||||||
* @noinspection PhpUnused
|
* @noinspection PhpUnused
|
||||||
*/
|
*/
|
||||||
public function getName(): string
|
public function getName(): string
|
||||||
|
@ -410,7 +462,7 @@
|
||||||
/**
|
/**
|
||||||
* Returns the path of the configuration file on disk
|
* Returns the path of the configuration file on disk
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string The path of the configuration file
|
||||||
*/
|
*/
|
||||||
public function getPath(): string
|
public function getPath(): string
|
||||||
{
|
{
|
||||||
|
@ -420,7 +472,7 @@
|
||||||
/**
|
/**
|
||||||
* Returns the configuration
|
* Returns the configuration
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array The configuration
|
||||||
* @noinspection PhpUnused
|
* @noinspection PhpUnused
|
||||||
*/
|
*/
|
||||||
public function getConfiguration(): array
|
public function getConfiguration(): array
|
||||||
|
@ -431,11 +483,11 @@
|
||||||
/**
|
/**
|
||||||
* Returns a formatted yaml string of the current configuration
|
* Returns a formatted yaml string of the current configuration
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string The configuration in YAML format
|
||||||
*/
|
*/
|
||||||
public function toYaml(): string
|
public function toYaml(): string
|
||||||
{
|
{
|
||||||
return Yaml::dump($this->configuration, 4, 2);
|
return Yaml::dump($this->configuration, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -451,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -459,7 +511,7 @@
|
||||||
/**
|
/**
|
||||||
* Imports a YAML file into the configuration
|
* Imports a YAML file into the configuration
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path The path to the YAML file
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function import(string $path): void
|
public function import(string $path): void
|
||||||
|
@ -481,7 +533,7 @@
|
||||||
/**
|
/**
|
||||||
* Exports the configuration to a YAML file
|
* Exports the configuration to a YAML file
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path The path to export the configuration to
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function export(string $path): void
|
public function export(string $path): void
|
||||||
|
|
|
@ -4,20 +4,18 @@
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use JetBrains\PhpStorm\NoReturn;
|
use JetBrains\PhpStorm\NoReturn;
|
||||||
use ncc\Exceptions\InvalidPackageNameException;
|
|
||||||
use ncc\Exceptions\InvalidScopeException;
|
|
||||||
use ncc\Exceptions\PackageLockException;
|
|
||||||
use ncc\Exceptions\PackageNotFoundException;
|
|
||||||
use ncc\Runtime;
|
|
||||||
use OptsLib\Parse;
|
use OptsLib\Parse;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
use Symfony\Component\Yaml\Exception\ParseException;
|
use Symfony\Component\Yaml\Exception\ParseException;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
use function trigger_error;
|
||||||
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
|
private static ?string $version = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main entry point of the program
|
* Main entry point of the program
|
||||||
*
|
*
|
||||||
|
@ -40,6 +38,7 @@
|
||||||
$editor = $args['editor'] ?? @$args['e'] ?? null;
|
$editor = $args['editor'] ?? @$args['e'] ?? null;
|
||||||
$export = $args['export'] ?? null;
|
$export = $args['export'] ?? null;
|
||||||
$import = $args['import'] ?? null;
|
$import = $args['import'] ?? null;
|
||||||
|
$path = $args['path'] ?? null;
|
||||||
|
|
||||||
if($configuration_name === null)
|
if($configuration_name === null)
|
||||||
{
|
{
|
||||||
|
@ -53,9 +52,16 @@
|
||||||
if(!file_exists($configuration->getPath()))
|
if(!file_exists($configuration->getPath()))
|
||||||
{
|
{
|
||||||
print(sprintf('Configuration \'%s\' does not exist, aborting' . PHP_EOL, $configuration->getName()));
|
print(sprintf('Configuration \'%s\' does not exist, aborting' . PHP_EOL, $configuration->getName()));
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($path !== null)
|
||||||
|
{
|
||||||
|
print($configuration->getPath() . PHP_EOL);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
if($import !== null)
|
if($import !== null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -145,7 +151,7 @@
|
||||||
*/
|
*/
|
||||||
#[NoReturn] private static function help(): void
|
#[NoReturn] private static function help(): void
|
||||||
{
|
{
|
||||||
print('ConfigLib v' . Runtime::getConstant('net.nosial.configlib', 'version') . PHP_EOL . PHP_EOL);
|
print('ConfigLib v' . self::getVersion() . PHP_EOL . PHP_EOL);
|
||||||
|
|
||||||
print('Usage: configlib [options]' . PHP_EOL);
|
print('Usage: configlib [options]' . PHP_EOL);
|
||||||
print(' -h, --help Displays the help menu' . PHP_EOL);
|
print(' -h, --help Displays the help menu' . PHP_EOL);
|
||||||
|
@ -155,6 +161,7 @@
|
||||||
print(' -e, --editor <editor> (Optional) The editor to use (eg; nano, vim, notepad) (External)' . PHP_EOL);
|
print(' -e, --editor <editor> (Optional) The editor to use (eg; nano, vim, notepad) (External)' . PHP_EOL);
|
||||||
print(' --export <file> (Optional) Exports the configuration to a file' . PHP_EOL);
|
print(' --export <file> (Optional) Exports the configuration to a file' . PHP_EOL);
|
||||||
print(' --import <file> (Optional) Imports the configuration from a file' . PHP_EOL);
|
print(' --import <file> (Optional) Imports the configuration from a file' . PHP_EOL);
|
||||||
|
print(' --path (Optional) Displays the configuration storage path' . PHP_EOL);
|
||||||
print(' --nc (Optional) Disables type casting (eg; \'true\' > True) will always be a string' . PHP_EOL);
|
print(' --nc (Optional) Disables type casting (eg; \'true\' > True) will always be a string' . PHP_EOL);
|
||||||
|
|
||||||
print('Examples:' . PHP_EOL . PHP_EOL);
|
print('Examples:' . PHP_EOL . PHP_EOL);
|
||||||
|
@ -164,6 +171,7 @@
|
||||||
print(' configlib --conf test --editor nano Edit the configuration' . PHP_EOL);
|
print(' configlib --conf test --editor nano Edit the configuration' . PHP_EOL);
|
||||||
print(' configlib --conf test --export out.json Export the configuration' . PHP_EOL);
|
print(' configlib --conf test --export out.json Export the configuration' . PHP_EOL);
|
||||||
print(' configlib --conf test --import in.json Import a configuration' . PHP_EOL);
|
print(' configlib --conf test --import in.json Import a configuration' . PHP_EOL);
|
||||||
|
print(' configlib --conf test --path Displays the configuration storage path' . PHP_EOL);
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
@ -174,10 +182,6 @@
|
||||||
* @param array $args
|
* @param array $args
|
||||||
* @param Configuration $configuration
|
* @param Configuration $configuration
|
||||||
* @return void
|
* @return void
|
||||||
* @throws InvalidPackageNameException
|
|
||||||
* @throws InvalidScopeException
|
|
||||||
* @throws PackageLockException
|
|
||||||
* @throws PackageNotFoundException
|
|
||||||
*/
|
*/
|
||||||
#[NoReturn] private static function edit(array $args, Configuration $configuration): void
|
#[NoReturn] private static function edit(array $args, Configuration $configuration): void
|
||||||
{
|
{
|
||||||
|
@ -196,21 +200,22 @@
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(!file_exists(Runtime::getDataPath('net.nosial.configlib') . DIRECTORY_SEPARATOR . 'tmp'))
|
$temporary_directory = sys_get_temp_dir();
|
||||||
|
if(!file_exists($temporary_directory . DIRECTORY_SEPARATOR . 'configlib'))
|
||||||
{
|
{
|
||||||
if (!mkdir($concurrentDirectory = Runtime::getDataPath('net.nosial.configlib') . DIRECTORY_SEPARATOR . 'tmp', 0777, true) && !is_dir($concurrentDirectory))
|
if (!mkdir($concurrentDirectory = $temporary_directory . DIRECTORY_SEPARATOR . 'configlib', 0777, true) && !is_dir($concurrentDirectory))
|
||||||
{
|
{
|
||||||
throw new RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
|
throw new RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!file_exists(Runtime::getDataPath('net.nosial.configlib') . DIRECTORY_SEPARATOR . 'tmp'))
|
if(!file_exists($temporary_directory . DIRECTORY_SEPARATOR . 'configlib'))
|
||||||
{
|
{
|
||||||
print('Unable to create the temporary path to use' . PHP_EOL);
|
print('Unable to create the temporary path to use' . PHP_EOL);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$tempPath = Runtime::getDataPath('net.nosial.configlib') . DIRECTORY_SEPARATOR . 'tmp';
|
$tempPath = $temporary_directory . DIRECTORY_SEPARATOR . 'configlib';
|
||||||
}
|
}
|
||||||
|
|
||||||
$fs = new Filesystem();
|
$fs = new Filesystem();
|
||||||
|
@ -276,4 +281,30 @@
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the current version of the library. If the version is not set, it checks
|
||||||
|
* if the CONFIGLIB_VERSION constant is defined. If neither is available, it returns 'Unknown'
|
||||||
|
* and triggers a user warning.
|
||||||
|
*
|
||||||
|
* @return string The current version of the library.
|
||||||
|
* @noinspection PhpUndefinedConstantInspection
|
||||||
|
*/
|
||||||
|
public static function getVersion(): string
|
||||||
|
{
|
||||||
|
if(self::$version !== null)
|
||||||
|
{
|
||||||
|
return self::$version;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(defined('CONFIGLIB_VERSION'))
|
||||||
|
{
|
||||||
|
self::$version = CONFIGLIB_VERSION;
|
||||||
|
return self::$version;
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$version = 'Unknown';
|
||||||
|
trigger_error('ConfigLib version is unknown', E_USER_WARNING);
|
||||||
|
return self::$version;
|
||||||
|
}
|
||||||
}
|
}
|
107
tests/ConfigLib/ConfigurationTest.php
Normal file
107
tests/ConfigLib/ConfigurationTest.php
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace ConfigLib;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class ConfigurationTest extends TestCase
|
||||||
|
{
|
||||||
|
public static function setUpBeforeClass(): void
|
||||||
|
{
|
||||||
|
$config = new Configuration('test');
|
||||||
|
|
||||||
|
if(file_exists($config->getPath()))
|
||||||
|
{
|
||||||
|
unlink($config->getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConstruct(): void
|
||||||
|
{
|
||||||
|
$config = new Configuration();
|
||||||
|
$this->assertInstanceOf(Configuration::class, $config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetExists(): void
|
||||||
|
{
|
||||||
|
$config = new Configuration('test');
|
||||||
|
|
||||||
|
$this->assertTrue($config->set('key1.key2', 'value', true));
|
||||||
|
$this->assertEquals('value', $config->get('key1.key2'));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetNotExists(): void
|
||||||
|
{
|
||||||
|
$config = new Configuration('test');
|
||||||
|
$this->assertFalse($config->set('key1.key3', 'value'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetInvalidKey(): void
|
||||||
|
{
|
||||||
|
$config = new Configuration('test');
|
||||||
|
$this->assertFalse($config->set('invalid\key', 'value'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetExists(): void
|
||||||
|
{
|
||||||
|
$config = new Configuration('test');
|
||||||
|
$config->set('key1.key2', 'value');
|
||||||
|
$this->assertEquals('value', $config->get('key1.key2'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* Test get method when provided with existing key
|
||||||
|
*/
|
||||||
|
public function testGetMethodWithValidKey(): void
|
||||||
|
{
|
||||||
|
$config = new Configuration('test');
|
||||||
|
$this->assertTrue($config->set('key1.key2', 'value', true));
|
||||||
|
$this->assertEquals('value', $config->get('key1.key2'));
|
||||||
|
$this->assertTrue($config->set('foo.fizz_buzz', 'value', true));
|
||||||
|
$this->assertEquals('value', $config->get('foo.fizz_buzz'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* Test get method when provided with non-existing key
|
||||||
|
*/
|
||||||
|
public function testGetMethodWithInvalidKey(): void
|
||||||
|
{
|
||||||
|
$config = new Configuration('test');
|
||||||
|
$this->assertNull($config->get('non.existing.key'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* Test get method when key format is not valid
|
||||||
|
*/
|
||||||
|
public function testGetMethodWithIncorrectKeyFormat(): void
|
||||||
|
{
|
||||||
|
$config = new Configuration('test');
|
||||||
|
$this->assertNull($config->get('incorrect\format'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* Test get method when provided with existing key and expecting the default value to be returned
|
||||||
|
*/
|
||||||
|
public function testGetMethodWithValidKeyExpectingDefaultValue(): void
|
||||||
|
{
|
||||||
|
$config = new Configuration('test');
|
||||||
|
$config->set('key1.key2', null);
|
||||||
|
$this->assertEquals('default', $config->get('key1.key2', 'default'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* Test setDefault method when non-existing key is provided
|
||||||
|
*/
|
||||||
|
public function testSetDefaultWithNonExistingKey(): void
|
||||||
|
{
|
||||||
|
$config = new Configuration('test');
|
||||||
|
$this->assertTrue($config->setDefault('non.existing.key', 'default'));
|
||||||
|
$this->assertEquals('default', $config->get('non.existing.key'));
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,14 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
require 'ncc';
|
|
||||||
import('net.nosial.configlib');
|
|
||||||
|
|
||||||
$config = new \ConfigLib\Configuration('test');
|
|
||||||
|
|
||||||
$config->setDefault('database.host', '127.0.0.1');
|
|
||||||
$config->setDefault('database.port', 3306);
|
|
||||||
$config->setDefault('database.username', 'root');
|
|
||||||
$config->setDefault('database.password', null);
|
|
||||||
$config->setDefault('database.name', 'test');
|
|
||||||
|
|
||||||
$config->save();
|
|
|
@ -1,11 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
require 'ncc';
|
|
||||||
import('net.nosial.configlib');
|
|
||||||
|
|
||||||
$config = new \ConfigLib\Configuration('test');
|
|
||||||
|
|
||||||
$config->set('database.host', '192.168.1.1');
|
|
||||||
$config->set('database.username', 'super_root');
|
|
||||||
|
|
||||||
$config->save();
|
|
|
@ -1,8 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
require 'ncc';
|
|
||||||
import('net.nosial.configlib');
|
|
||||||
|
|
||||||
$config = new \ConfigLib\Configuration('test');
|
|
||||||
|
|
||||||
var_dump($config->getConfiguration());
|
|
Loading…
Add table
Reference in a new issue