Compare commits
207 commits
Author | SHA1 | Date | |
---|---|---|---|
6909790de6 | |||
db631bd778 | |||
1b8b3f8ad7 | |||
ccb1ef6971 | |||
ead20f7924 | |||
487eb70b0b | |||
1e45b47f0f | |||
d861998f4f | |||
![]() |
d57666b40d | ||
![]() |
05882205f0 | ||
![]() |
2bd78a1d79 | ||
![]() |
81894af835 | ||
![]() |
b975508d07 | ||
![]() |
1ef96c3c4c | ||
![]() |
2dad5133bd | ||
![]() |
544d4ebdf6 | ||
![]() |
41947069be | ||
![]() |
11aaa39eaa | ||
bdcf510089 | |||
278b3d0e2e | |||
771748636d | |||
![]() |
3b5a3882f6 | ||
![]() |
77c668f7b6 | ||
![]() |
c40c7ce8fe | ||
![]() |
f5433c6bf9 | ||
![]() |
bc86e5a65d | ||
![]() |
f8ede74764 | ||
![]() |
c87ebf14dd | ||
![]() |
e48e6a55e4 | ||
![]() |
08c770c9e1 | ||
![]() |
e2a8dbfe27 | ||
![]() |
91fe129bf4 | ||
![]() |
44dc1498f7 | ||
![]() |
c659baa9ce | ||
![]() |
1b33b83926 | ||
![]() |
9303158674 | ||
![]() |
d249e99448 | ||
![]() |
3f2f325bcc | ||
![]() |
2a20786755 | ||
![]() |
8ceb6756a4 | ||
![]() |
51bdb22540 | ||
![]() |
36d8e6f8c6 | ||
![]() |
9136396700 | ||
![]() |
e225add40b | ||
![]() |
33865d7e48 | ||
![]() |
cba6942cca | ||
![]() |
29e0a6e4ae | ||
![]() |
cba5f7041a | ||
![]() |
1ddb042175 | ||
![]() |
093e3341e1 | ||
![]() |
80a019452f | ||
![]() |
b30ddbdc28 | ||
![]() |
e829a839d1 | ||
![]() |
d813ef7b94 | ||
![]() |
09fb388ee7 | ||
![]() |
87290232f5 | ||
![]() |
adbd1d1751 | ||
![]() |
273df6ebb4 | ||
![]() |
d2baa2d580 | ||
![]() |
b2ef33d48f | ||
![]() |
7e79bba762 | ||
![]() |
45c58c0568 | ||
![]() |
3b0f1a805c | ||
![]() |
3640befdcc | ||
![]() |
798fe9e797 | ||
![]() |
140b0f2aff | ||
![]() |
64fdc3b5bd | ||
![]() |
23bd2c6636 | ||
![]() |
b29c83f276 | ||
![]() |
5eeb0d270d | ||
![]() |
2c5733c5c0 | ||
![]() |
e041ca2c20 | ||
![]() |
c9e4a6741a | ||
![]() |
634f50e317 | ||
![]() |
6d2d827de2 | ||
![]() |
1bb6189e57 | ||
![]() |
4db07af9bb | ||
![]() |
b93e07bc3d | ||
![]() |
9418125722 | ||
![]() |
7494ead7b3 | ||
![]() |
170cb4bf6d | ||
![]() |
dda710119c | ||
![]() |
be70823a79 | ||
![]() |
923117999b | ||
![]() |
a1404490bb | ||
![]() |
e556282f61 | ||
![]() |
cdd3516766 | ||
![]() |
9831b9dca1 | ||
![]() |
dd48100f06 | ||
![]() |
910477df8e | ||
![]() |
d59f5fb6e0 | ||
![]() |
4e174821fc | ||
![]() |
c7b007c704 | ||
![]() |
272fc8524e | ||
![]() |
5e173b7cc0 | ||
![]() |
91a25390fa | ||
![]() |
bcb26d1eec | ||
![]() |
1389b61fa2 | ||
![]() |
16ad69b9f2 | ||
![]() |
3aedd2d94d | ||
![]() |
b2d2a1ea15 | ||
![]() |
604e1fd3e7 | ||
![]() |
3950655024 | ||
![]() |
da8a6fac01 | ||
![]() |
943048785d | ||
![]() |
bdcf5160de | ||
![]() |
46fd39c51c | ||
![]() |
8e6acbbc70 | ||
![]() |
3adc1b81fb | ||
![]() |
3160ddfa27 | ||
![]() |
ae8021bb3a | ||
![]() |
b6cdb2a78c | ||
![]() |
3e8af9c43c | ||
![]() |
e5ceb9bbf7 | ||
![]() |
bcefb6c56a | ||
![]() |
3c1286d9c2 | ||
![]() |
d8247b0760 | ||
![]() |
68cfed8a05 | ||
![]() |
04a85900fd | ||
![]() |
836d0f33eb | ||
![]() |
ffc6588ff9 | ||
![]() |
0afc45f300 | ||
![]() |
61158ff802 | ||
![]() |
ad9e406657 | ||
![]() |
27c79b1170 | ||
![]() |
7e224d91b2 | ||
![]() |
d0e484631f | ||
![]() |
1bcfe90bea | ||
![]() |
e624663f62 | ||
![]() |
8b64a48a5f | ||
![]() |
24e67061f1 | ||
![]() |
6398b2958b | ||
![]() |
5ea0235515 | ||
![]() |
b291604145 | ||
![]() |
714228ad2e | ||
![]() |
aa65dd73cf | ||
![]() |
dfa6b50299 | ||
![]() |
8f87541a64 | ||
6482d06ba2 | |||
9fe2dc48fe | |||
039147c8a8 | |||
863dffafe7 | |||
0c4ef17bbf | |||
ac81f2f26d | |||
66e6e1528d | |||
c24fce2ee5 | |||
ae21d98290 | |||
d379956437 | |||
2bd2d757fd | |||
87844ab00a | |||
ec6b368a82 | |||
2efa6654e6 | |||
21c2405a27 | |||
87a8ca24a1 | |||
492548d81f | |||
9c06378258 | |||
0d9f3d37a3 | |||
e02f1f56dc | |||
12f0ff2ffa | |||
e11f95a22a | |||
fd928ffc99 | |||
3db33006b7 | |||
b5d35ed20e | |||
a2149cdb66 | |||
28ff80dd41 | |||
86cf7467af | |||
3d44562241 | |||
5b24fe267d | |||
14ec2e06b2 | |||
71ffed1a3f | |||
d884d0fbda | |||
baf11f5cb9 | |||
e1013f6c15 | |||
718c6ff8d8 | |||
5dd98083d6 | |||
d612c67cb0 | |||
42473390e8 | |||
cfc93aa066 | |||
91103c1470 | |||
9885d98b55 | |||
321fef4228 | |||
c687d0394d | |||
2a16b2de6b | |||
e98b949b7d | |||
7e5cdf4d64 | |||
90535a3a35 | |||
69de79ccf4 | |||
7c9f63955a | |||
1ba50cc7ee | |||
f9047dd0d0 | |||
a65b76b6bf | |||
957d9a9510 | |||
d2635b19fd | |||
76f12bb0a3 | |||
7befd995e7 | |||
b2234d5040 | |||
27d1609b23 | |||
de1e199dff | |||
aa6800e96a | |||
a2cd98ba98 | |||
27baeca112 | |||
4f7aa7a859 | |||
3ebdeb0cba | |||
bcc6f45eb4 | |||
698d2e7a1f | |||
89d3af8680 | |||
12d7744e1e |
136
.github/workflows/ci.yml
vendored
Executable file
|
@ -0,0 +1,136 @@
|
||||||
|
name: CI Pipeline
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- '**'
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- '**'
|
||||||
|
release:
|
||||||
|
types:
|
||||||
|
- created
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up PHP
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: '8.3'
|
||||||
|
extensions: mbstring, ctype, common, zip
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y git libpq-dev libzip-dev zip make wget gnupg
|
||||||
|
|
||||||
|
- 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
|
||||||
|
sudo mv phive.phar /usr/local/bin/phive
|
||||||
|
|
||||||
|
- name: Install PHPAB
|
||||||
|
run: sudo phive install phpab --global --trust-gpg-keys 0x2A8299CE842DD38C
|
||||||
|
|
||||||
|
- name: Build project
|
||||||
|
run: make redist
|
||||||
|
|
||||||
|
- name: Find NCC build directory
|
||||||
|
id: find-ncc-dir
|
||||||
|
run: echo "NCC_DIR=$(find build/ -type d -name 'ncc_*' | head -n 1)" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Upload NCC build directory
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: ncc-build
|
||||||
|
path: ${{ env.NCC_DIR }}
|
||||||
|
|
||||||
|
- name: Create redist.zip
|
||||||
|
run: zip -r redist.zip ${{ env.NCC_DIR }}
|
||||||
|
|
||||||
|
- name: Upload redist.zip
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: redist-zip
|
||||||
|
path: redist.zip
|
||||||
|
|
||||||
|
- name: Build Debian package
|
||||||
|
run: make deb
|
||||||
|
|
||||||
|
- name: Find Debian package
|
||||||
|
id: find-deb
|
||||||
|
run: echo "DEB_FILE=$(find build/ -type f -name '*.deb' | head -n 1)" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Upload Debian package
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: ncc-deb
|
||||||
|
path: ${{ env.DEB_FILE }}
|
||||||
|
|
||||||
|
test-install:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: build
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Download NCC build directory
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: ncc-build
|
||||||
|
path: build
|
||||||
|
|
||||||
|
- name: Set up PHP
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: '8.3'
|
||||||
|
extensions: mbstring, ctype, common, zip
|
||||||
|
|
||||||
|
- name: Test NCC installation
|
||||||
|
run: |
|
||||||
|
ls -l build
|
||||||
|
sudo php build/INSTALL --auto
|
||||||
|
|
||||||
|
upload-release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: build
|
||||||
|
if: github.event_name == 'release' && github.event.action == 'created'
|
||||||
|
permissions: write-all
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Download redist.zip
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: redist-zip
|
||||||
|
path: .
|
||||||
|
|
||||||
|
- name: Download Debian package
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: ncc-deb
|
||||||
|
path: .
|
||||||
|
|
||||||
|
- name: Set DEB_FILE environment variable
|
||||||
|
run: echo "DEB_FILE=$(find . -type f -name '*.deb' | head -n 1)" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Upload redist.zip to release
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
files: redist.zip
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Upload ncc.deb to release
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
files: ${{ env.DEB_FILE }}
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
5
.gitignore
vendored
Normal file → Executable file
|
@ -8,7 +8,7 @@
|
||||||
build
|
build
|
||||||
|
|
||||||
# Autoload files
|
# Autoload files
|
||||||
src/ncc/ThirdParty/composer/semver/autoload_spl.php
|
src/ncc/ThirdParty/composer/Semver/autoload_spl.php
|
||||||
src/ncc/ThirdParty/defuse/php-encryption/autoload_spl.php
|
src/ncc/ThirdParty/defuse/php-encryption/autoload_spl.php
|
||||||
src/ncc/ThirdParty/jelix/version/autoload_spl.php
|
src/ncc/ThirdParty/jelix/version/autoload_spl.php
|
||||||
src/ncc/ThirdParty/nikic/PhpParser/autoload_spl.php
|
src/ncc/ThirdParty/nikic/PhpParser/autoload_spl.php
|
||||||
|
@ -29,3 +29,6 @@ src/ncc/autoload.php
|
||||||
tests/example_project/project.json
|
tests/example_project/project.json
|
||||||
tests/example_project/ncc
|
tests/example_project/ncc
|
||||||
tests/example_project/build
|
tests/example_project/build
|
||||||
|
/.phpunit.result.cache
|
||||||
|
/.idea/php-test-framework.xml
|
||||||
|
/.idea/gbrowser_project.xml
|
||||||
|
|
0
.gitlab-ci.yml
Normal file → Executable file
0
.idea/.gitignore
generated
vendored
Normal file → Executable file
0
.idea/.name
generated
Normal file → Executable file
0
.idea/Nosial Code Compiler.iml
generated
Normal file → Executable file
7
.idea/codeStyles/Project.xml
generated
Executable file
|
@ -0,0 +1,7 @@
|
||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<code_scheme name="Project" version="173">
|
||||||
|
<ScalaCodeStyleSettings>
|
||||||
|
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
|
||||||
|
</ScalaCodeStyleSettings>
|
||||||
|
</code_scheme>
|
||||||
|
</component>
|
0
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file → Executable file
0
.idea/copyright/Nosial.xml
generated
Normal file → Executable file
0
.idea/copyright/profiles_settings.xml
generated
Normal file → Executable file
0
.idea/encodings.xml
generated
Normal file → Executable file
0
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file → Executable file
0
.idea/modules.xml
generated
Normal file → Executable file
0
.idea/php-inspections-ea-ultimate.xml
generated
Normal file → Executable file
8
.idea/php.xml
generated
Normal file → Executable file
|
@ -12,10 +12,9 @@
|
||||||
<component name="PhpIncludePathManager">
|
<component name="PhpIncludePathManager">
|
||||||
<include_path>
|
<include_path>
|
||||||
<path value="/usr/share/php" />
|
<path value="/usr/share/php" />
|
||||||
<path value="$PROJECT_DIR$/../loglib" />
|
|
||||||
</include_path>
|
</include_path>
|
||||||
</component>
|
</component>
|
||||||
<component name="PhpProjectSharedConfiguration" php_language_level="8.2">
|
<component name="PhpProjectSharedConfiguration" php_language_level="8.3">
|
||||||
<option name="suggestChangeDefaultLanguageLevel" value="false" />
|
<option name="suggestChangeDefaultLanguageLevel" value="false" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PhpRuntimeConfiguration">
|
<component name="PhpRuntimeConfiguration">
|
||||||
|
@ -26,6 +25,11 @@
|
||||||
<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="" phpunit_phar_path="$USER_HOME$/phpunit.phar" />
|
||||||
|
</phpunit_settings>
|
||||||
|
</component>
|
||||||
<component name="PsalmOptionsConfiguration">
|
<component name="PsalmOptionsConfiguration">
|
||||||
<option name="transferred" value="true" />
|
<option name="transferred" value="true" />
|
||||||
</component>
|
</component>
|
||||||
|
|
0
.idea/runConfigurations/Build_Redist.xml
generated
Normal file → Executable file
0
.idea/runConfigurations/Rebuild_Autoloaders.xml
generated
Normal file → Executable file
0
.idea/scopes/Autoloaders.xml
generated
Normal file → Executable file
0
.idea/scopes/Installer_Source_files.xml
generated
Normal file → Executable file
0
.idea/scopes/NCC_Source_files.xml
generated
Normal file → Executable file
0
.idea/scopes/Symfony_Filesystem.xml
generated
Normal file → Executable file
0
.idea/scopes/Symfony_Process.xml
generated
Normal file → Executable file
0
.idea/scopes/Symfony_Uid.xml
generated
Normal file → Executable file
0
.idea/scopes/Symfony_Yaml.xml
generated
Normal file → Executable file
0
.idea/scopes/Symfony_polyfill_ctype.xml
generated
Normal file → Executable file
0
.idea/scopes/Symfony_polyfill_mbstring.xml
generated
Normal file → Executable file
0
.idea/scopes/Symfony_polyfill_uuid.xml
generated
Normal file → Executable file
0
.idea/scopes/Third_Party_Source_Files.xml
generated
Normal file → Executable file
0
.idea/scopes/defuse.xml
generated
Normal file → Executable file
0
.idea/scopes/defuse_php_encryption.xml
generated
Normal file → Executable file
0
.idea/scopes/jelix.xml
generated
Normal file → Executable file
0
.idea/scopes/jelix_version.xml
generated
Normal file → Executable file
0
.idea/scopes/nikic.xml
generated
Normal file → Executable file
0
.idea/scopes/nikic_PhpParser.xml
generated
Normal file → Executable file
0
.idea/scopes/theseer.xml
generated
Normal file → Executable file
0
.idea/scopes/theseer_Autoload.xml
generated
Normal file → Executable file
0
.idea/scopes/theseer_DirectoryScanner.xml
generated
Normal file → Executable file
0
.idea/vcs.xml
generated
Normal file → Executable file
0
.idea/webResources.xml
generated
Normal file → Executable file
186
CHANGELOG.md
Normal file → Executable file
|
@ -5,6 +5,190 @@ 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).
|
||||||
|
|
||||||
|
## [2.1.8] - 2025-03-17
|
||||||
|
|
||||||
|
This update introduces a temporary fix
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- (Temporary) removed the ability to delete cache files because it's deleting important files that are needed.
|
||||||
|
|
||||||
|
|
||||||
|
## [2.1.7] - 2025-03-17
|
||||||
|
|
||||||
|
This update introduces a quality of life improvement
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Refactor variable names for consistency and clarity in ShutdownHandler and PackageWriter classes
|
||||||
|
- Improve error handling in ShutdownHandler by logging warnings for cleanup failures
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Fixed issue in ArchiveExctractor where close() may be called on a already closed resource
|
||||||
|
|
||||||
|
|
||||||
|
## [2.1.6] - 2024-10-29
|
||||||
|
|
||||||
|
This update introduces critical bug fixes
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Validate package instance before checking execution policy
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## [2.1.5] - 2024-10-14
|
||||||
|
|
||||||
|
This update introduces a critical bug fix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## [2.1.4] - 2024-10-13
|
||||||
|
|
||||||
|
This update introduces minor bug fixes & improvements
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Added new constant `%DEFAULT_BUILD_CONFIGURATION%` which points to the project's default build configuration
|
||||||
|
- Added new dynamic constant `%BUILD_OUTPUT_PATH%` which can be used as `%BUILD_OUTPUT_PATH%:release` to show the
|
||||||
|
output path of a specific build configuration
|
||||||
|
- Refactor CI templates to support dynamic build targets
|
||||||
|
- Added template `phpexe` & `phpgz` for generating executable binaries and compressed executables for the project
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Refactor phpmake template to support dynamic build targets
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- ncc will now correctly handle package execution where the main unit is not defined in the package instead of
|
||||||
|
throwing an exception.
|
||||||
|
- Executable Compiler will now correctly create a directory if it does not exist when compiling a package using gcc
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## [2.1.3] - 2024-09-27
|
||||||
|
|
||||||
|
This update introduces bug fixes
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Null-pointer fix
|
||||||
|
|
||||||
|
|
||||||
|
## [2.1.2] - 2024-09-27
|
||||||
|
|
||||||
|
This update introduces bug fixes
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Add getter methods for installation lifecycle steps
|
||||||
|
- Added pre-install & post-install execution unit handling
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Updated DocStrings in PackageManager
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Fixed incorrect enum usage in RepositoryMenu
|
||||||
|
|
||||||
|
|
||||||
|
## [2.1.1] - 2024-09-24
|
||||||
|
|
||||||
|
This update introduces a couple of new features and quality of life improvements
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Added new PHP template `phpunit` for generating PhpUnit tests for the project
|
||||||
|
- Added new PHP template `phpmake` for generating a Makefile for the project
|
||||||
|
- Added new PHP template `phplib_full` That combines `phplib`, `phpmake` and `phpunit` templates
|
||||||
|
- Added new PHP template `phpcli_full` That combines `phpcli`, `phplib`, `phpmake` and `phpunit` templates
|
||||||
|
- Added new PHP template `phpci_github` that generates a Github CI workflow for the project
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- The template `phpcli` no longer includes a Makefile, instead use `phpmake` to generate a Makefile for the project
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Fixed incorrect enum usage with a logging method call.
|
||||||
|
|
||||||
|
|
||||||
|
## [2.1.0] - 2024-09-20
|
||||||
|
|
||||||
|
This update introduces a refactored code-base, code quality improvements, and better exception handling.
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Added Test unit tests/ncc/Objects/Package/ComponentTest.php
|
||||||
|
- Added Test unit tests/ncc/Utilities/ResolverTest.php
|
||||||
|
- Added Test unit tests/ncc/Utilities/SecurityTest.php
|
||||||
|
- Added Test unit tests/ncc/Utilities/ValidateTest.php
|
||||||
|
- Add support for runtime constants
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Convert Versions constants to enum cases
|
||||||
|
- Update Scopes to enum and adjust scope checks
|
||||||
|
- Convert Runners class to enum with string cases
|
||||||
|
- Convert RegexPatterns constants to enum cases
|
||||||
|
- Convert ProjectTemplates constants to enum cases
|
||||||
|
- Convert PackageStructureVersions constants to enum cases
|
||||||
|
- Convert PackageStructure constants to enum cases
|
||||||
|
- Convert PackageDirectory constants to enum cases
|
||||||
|
- Convert LogLevel constants to enum cases
|
||||||
|
- Convert FileDescriptor constants to enum cases
|
||||||
|
- Convert ExceptionCodes constants to enum cases
|
||||||
|
- Convert ConsoleColors constants to enum cases
|
||||||
|
- Convert CompilerExtensions constants to enum cases
|
||||||
|
- Convert RepositoryType constants to enum cases
|
||||||
|
- Convert RepositoryResultType constants to enum cases
|
||||||
|
- Convert ProjectType constants to enum cases
|
||||||
|
- Convert HttpRequestType constants to enum cases
|
||||||
|
- Convert ComposerStabilityTypes constants to enum cases
|
||||||
|
- Convert ComposerPackageTypes constants to enum cases
|
||||||
|
- Convert ComponentDataType constants to enum cases
|
||||||
|
- Convert BuildOutputType constants to enum cases
|
||||||
|
- Convert AuthenticationType constants to enum cases
|
||||||
|
- Convert RuntimeConstants constants to enum cases
|
||||||
|
- Convert InstallConstants constants to enum cases
|
||||||
|
- Convert DateTimeConstants constants to enum cases
|
||||||
|
- Convert BuildConstants constants to enum cases
|
||||||
|
- Convert AssemblyConstants constants to enum cases
|
||||||
|
- Convert ProjectOptions constants to enum cases
|
||||||
|
- Convert InstallPackageOptions constants to enum cases
|
||||||
|
- Convert InitializeProjectOptions constants to enum cases
|
||||||
|
- Convert ComponentDecodeOptions constants to enum cases
|
||||||
|
- Convert BuildConfigurationValues constants to enum cases
|
||||||
|
- Convert BuildConfigurationOptions constants to enum cases
|
||||||
|
- Convert CompressionOptions constants to enum cases
|
||||||
|
- Convert PackageFlags constants to enum cases
|
||||||
|
- Convert NccBuildFlags constants to enum cases
|
||||||
|
- Convert ComponentFlags constants to enum cases
|
||||||
|
- Refactor flag handling to use PackageFlags enum directly
|
||||||
|
- Refactor checkLogLevel to correctly utilize LogLevel cases
|
||||||
|
- Refactor code to improve readability in Resolver.php
|
||||||
|
- Update PHP include paths in project configuration
|
||||||
|
- Refactor logging level checks to use LogLevel enum directly
|
||||||
|
- Refactor log level parsing with enum method
|
||||||
|
- Refactor log level checking to enum method
|
||||||
|
- Updated Symfony/Filesystem from version 6.3.1 to 7.1.2
|
||||||
|
- Refactor ProjectType handling
|
||||||
|
- Validate and enforce repository type enum usage
|
||||||
|
- Updated Composer/Semver to 3.4.3
|
||||||
|
- Rename 'semver' directory to 'Semver' in composer package
|
||||||
|
- Refactor project constants handling in NccCompiler
|
||||||
|
- Updated Symfony/Yaml to version 7.1.4
|
||||||
|
- Updated Symfony/Uid to version 7.1.4
|
||||||
|
- Updated Symfony/Process to version 7.1.3
|
||||||
|
- Updated Symfony/polyfill-ctype to version 1.31.0
|
||||||
|
- Updated Symfony/polyfill-mbstring to version 1.31.0
|
||||||
|
- Updated Symfony/polyfill-uuid to version 1.31.0
|
||||||
|
- Updated nikic/PhpParser to version 5.2.0
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Fixed Division by zero in PackageManager
|
||||||
|
- Fixed runner argument passing for ExecCommand
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
- Removed EncoderType enum file, unused.
|
||||||
|
- Removed PackageStandardVersions.php
|
||||||
|
- Removed ConstantReferences.php
|
||||||
|
- Removed HttpStatusCodes.php
|
||||||
|
- Removed CompilerExtensionDefaultVersions.php
|
||||||
|
- Removed RemoteSourceType
|
||||||
|
- Removed DependencySourceType
|
||||||
|
- Removed BuiltinRemoteSourceType
|
||||||
|
- Removed RuntimeImportOptions
|
||||||
|
- Remove ComponentFileExtensions enum
|
||||||
|
- Remove unused import and redundant scope validation method
|
||||||
|
|
||||||
## [2.0.3] - 2023-10-17
|
## [2.0.3] - 2023-10-17
|
||||||
|
|
||||||
This update includes enhanced support for PHP statements in AST traversal, a friendly CLI Progress Bar, and fixes
|
This update includes enhanced support for PHP statements in AST traversal, a friendly CLI Progress Bar, and fixes
|
||||||
|
@ -20,7 +204,7 @@ The changes improve the system's efficiency, error resilience, and user experien
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- When finding package versions in the package lock, ncc will try to find a satisfying version rather than the exact
|
- When finding package versions in the package lock, ncc will try to find a satisfying version rather than the exact
|
||||||
version, this is to prevent errors when the package lock contains a version that is not available in the repository.
|
version, this is to prevent[CHANGELOG.md](CHANGELOG.md) errors when the package lock contains a version that is not available in the repository.
|
||||||
- Fixed issue when registering ncc's extension, when using the INSTALLER, the installation path used in the process
|
- Fixed issue when registering ncc's extension, when using the INSTALLER, the installation path used in the process
|
||||||
appears to be incorrect, added a optional parameter to the `registerExtension` method to allow the installer to pass
|
appears to be incorrect, added a optional parameter to the `registerExtension` method to allow the installer to pass
|
||||||
the correct installation path.
|
the correct installation path.
|
||||||
|
|
0
CODE_OF_CONDUCT.md
Normal file → Executable file
0
CONTRIBUTING.md
Normal file → Executable file
2
DOCUMENTATION.md
Normal file → Executable file
|
@ -62,7 +62,7 @@ basic usage, standards, and much more.
|
||||||
* [Package Metadata (metadata)](#package-metadata-metadata)
|
* [Package Metadata (metadata)](#package-metadata-metadata)
|
||||||
* [Assembly Information (assembly)](#assembly-information-assembly)
|
* [Assembly Information (assembly)](#assembly-information-assembly)
|
||||||
* [Package Dependencies (dependencies)](#package-dependencies-dependencies)
|
* [Package Dependencies (dependencies)](#package-dependencies-dependencies)
|
||||||
* [Execution Units (execution_units)](#execution-units-executionunits)
|
* [Execution Units (execution_units)](#execution-units-execution_units)
|
||||||
* [Building Projects (build)](#building-projects-build)
|
* [Building Projects (build)](#building-projects-build)
|
||||||
* [Execute (exec)](#execute-exec)
|
* [Execute (exec)](#execute-exec)
|
||||||
* [Project Configuration (package.json)](#project-configuration-packagejson)
|
* [Project Configuration (package.json)](#project-configuration-packagejson)
|
||||||
|
|
0
Dockerfile
Normal file → Executable file
0
Dockerfile.debian
Normal file → Executable file
0
LICENSE
Normal file → Executable file
2
Makefile
Normal file → Executable file
|
@ -18,7 +18,7 @@ DEBIAN_PACKAGE_BUILD_PATH := $(BUILD_PATH)/ncc_$(BUILD_VERSION)_all.deb
|
||||||
|
|
||||||
# List of paths for autoloading
|
# List of paths for autoloading
|
||||||
AUTOLOAD_PATHS := $(addprefix $(SRC_PATH)/ncc/ThirdParty/, \
|
AUTOLOAD_PATHS := $(addprefix $(SRC_PATH)/ncc/ThirdParty/, \
|
||||||
composer/semver \
|
composer/Semver \
|
||||||
defuse/php-encryption \
|
defuse/php-encryption \
|
||||||
jelix/version \
|
jelix/version \
|
||||||
nikic/PhpParser \
|
nikic/PhpParser \
|
||||||
|
|
13
README.md
Normal file → Executable file
|
@ -6,6 +6,19 @@ Nosial Code Compiler is a package compiler, manager & installer for PHP. Allowin
|
||||||
versions of php packages on your system that your PHP programs/projects can share and use. Additionally, ncc also allows
|
versions of php packages on your system that your PHP programs/projects can share and use. Additionally, ncc also allows
|
||||||
you to create a redistributable package of your PHP program/project in the form of a `.ncc` binary package file.
|
you to create a redistributable package of your PHP program/project in the form of a `.ncc` binary package file.
|
||||||
|
|
||||||
|
## 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/ncc)
|
||||||
|
- [GitHub](https://github.com/nosial/ncc)
|
||||||
|
- [Codeberg](https://codeberg.org/nosial/ncc)
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
|
|
0
assets/compiler_process.png
Normal file → Executable file
Before Width: | Height: | Size: 57 KiB After Width: | Height: | Size: 57 KiB |
0
assets/data_structure.png
Normal file → Executable file
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
0
assets/execution_process.png
Normal file → Executable file
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
0
assets/header_structure.png
Normal file → Executable file
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 8.2 KiB |
0
assets/icon/ncc.svg
Normal file → Executable file
Before Width: | Height: | Size: 683 B After Width: | Height: | Size: 683 B |
0
assets/icon/ncc@1024px.png
Normal file → Executable file
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
0
assets/icon/ncc@128px.png
Normal file → Executable file
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
0
assets/icon/ncc@16px.png
Normal file → Executable file
Before Width: | Height: | Size: 351 B After Width: | Height: | Size: 351 B |
0
assets/icon/ncc@256px.png
Normal file → Executable file
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
0
assets/icon/ncc@32px.png
Normal file → Executable file
Before Width: | Height: | Size: 504 B After Width: | Height: | Size: 504 B |
0
assets/icon/ncc@512px.png
Normal file → Executable file
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 6.8 KiB |
0
assets/icon/ncc@64px.png
Normal file → Executable file
Before Width: | Height: | Size: 820 B After Width: | Height: | Size: 820 B |
0
assets/package_structure.png
Normal file → Executable file
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 51 KiB |
9
bootstrap.php
Executable file
|
@ -0,0 +1,9 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$autoload_path = __DIR__ . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'ncc' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||||
|
if(!file_exists($autoload_path))
|
||||||
|
{
|
||||||
|
throw new Exception("Autoload file not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
require $autoload_path;
|
0
old_docker/Dockerfile
Normal file → Executable file
0
old_docker/Dockerfile.debian
Normal file → Executable file
0
old_docker/note.txt
Normal file → Executable file
11
phpunit.xml
Executable file
|
@ -0,0 +1,11 @@
|
||||||
|
<phpunit bootstrap="bootstrap.php">
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="ncc Test Suite">
|
||||||
|
<directory>tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
<php>
|
||||||
|
<ini name="error_reporting" value="-1"/>
|
||||||
|
<server name="KERNEL_DIR" value="app/"/>
|
||||||
|
</php>
|
||||||
|
</phpunit>
|
2
src/autoload/autoload.php
Normal file → Executable file
|
@ -13,7 +13,7 @@
|
||||||
$third_party_path = __DIR__ . DIRECTORY_SEPARATOR . 'ThirdParty' . DIRECTORY_SEPARATOR;
|
$third_party_path = __DIR__ . DIRECTORY_SEPARATOR . 'ThirdParty' . DIRECTORY_SEPARATOR;
|
||||||
$target_files = [
|
$target_files = [
|
||||||
__DIR__ . DIRECTORY_SEPARATOR . 'autoload_spl.php',
|
__DIR__ . DIRECTORY_SEPARATOR . 'autoload_spl.php',
|
||||||
$third_party_path . 'composer' . DIRECTORY_SEPARATOR . 'semver' . DIRECTORY_SEPARATOR . 'autoload_spl.php',
|
$third_party_path . 'composer' . DIRECTORY_SEPARATOR . 'Semver' . DIRECTORY_SEPARATOR . 'autoload_spl.php',
|
||||||
$third_party_path . 'defuse' . DIRECTORY_SEPARATOR . 'php-encryption' . DIRECTORY_SEPARATOR . 'autoload_spl.php',
|
$third_party_path . 'defuse' . DIRECTORY_SEPARATOR . 'php-encryption' . DIRECTORY_SEPARATOR . 'autoload_spl.php',
|
||||||
$third_party_path . 'jelix' . DIRECTORY_SEPARATOR . 'version' . DIRECTORY_SEPARATOR . 'autoload_spl.php',
|
$third_party_path . 'jelix' . DIRECTORY_SEPARATOR . 'version' . DIRECTORY_SEPARATOR . 'autoload_spl.php',
|
||||||
$third_party_path . 'nikic' . DIRECTORY_SEPARATOR . 'PhpParser' . DIRECTORY_SEPARATOR . 'autoload_spl.php',
|
$third_party_path . 'nikic' . DIRECTORY_SEPARATOR . 'PhpParser' . DIRECTORY_SEPARATOR . 'autoload_spl.php',
|
||||||
|
|
0
src/config/default_repositories.json
Normal file → Executable file
0
src/config/ncc.yaml
Normal file → Executable file
2
src/debian/control
Normal file → Executable file
|
@ -2,7 +2,7 @@ Package: ncc
|
||||||
Source: ncc
|
Source: ncc
|
||||||
Section: devel
|
Section: devel
|
||||||
Priority: optional
|
Priority: optional
|
||||||
Version: 2.0.3
|
Version: 2.0.4
|
||||||
Maintainer: netkas <netkas@nosial.net>
|
Maintainer: netkas <netkas@nosial.net>
|
||||||
Build-Depends: debhelper-compat (= 13)
|
Build-Depends: debhelper-compat (= 13)
|
||||||
Standards-Version: 4.5.1
|
Standards-Version: 4.5.1
|
||||||
|
|
0
src/debian/copyright
Normal file → Executable file
0
src/debian/postinst
Normal file → Executable file
0
src/debian/postrm
Normal file → Executable file
0
src/installer/generate_build_files.php
Normal file → Executable file
0
src/installer/hash_check.php
Normal file → Executable file
0
src/installer/installer
Normal file → Executable file
0
src/installer/ncc-package.xml
Normal file → Executable file
0
src/installer/ncc.desktop
Normal file → Executable file
4
src/ncc/CLI/Commands/BuildCommand.php
Normal file → Executable file
|
@ -75,7 +75,7 @@
|
||||||
|
|
||||||
if($output_path !== null)
|
if($output_path !== null)
|
||||||
{
|
{
|
||||||
$options[BuildConfigurationOptions::OUTPUT_FILE] = $output_path;
|
$options[BuildConfigurationOptions::OUTPUT_FILE->value] = $output_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the project
|
// Load the project
|
||||||
|
@ -92,7 +92,7 @@
|
||||||
// Build the project
|
// Build the project
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$build_configuration = $args['config'] ?? $args['c'] ?? BuildConfigurationValues::DEFAULT;
|
$build_configuration = $args['config'] ?? $args['c'] ?? BuildConfigurationValues::DEFAULT->value;
|
||||||
$output = $project_manager->build($build_configuration, $options);
|
$output = $project_manager->build($build_configuration, $options);
|
||||||
}
|
}
|
||||||
catch (Exception $e)
|
catch (Exception $e)
|
||||||
|
|
10
src/ncc/CLI/Commands/ExecCommand.php
Normal file → Executable file
|
@ -24,9 +24,11 @@
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use ncc\Classes\Runtime;
|
use ncc\Classes\Runtime;
|
||||||
|
use ncc\CLI\Main;
|
||||||
use ncc\Objects\CliHelpSection;
|
use ncc\Objects\CliHelpSection;
|
||||||
use ncc\Utilities\Console;
|
use ncc\Utilities\Console;
|
||||||
use ncc\Utilities\Functions;
|
use ncc\Utilities\Functions;
|
||||||
|
use ncc\Utilities\Resolver;
|
||||||
|
|
||||||
class ExecCommand
|
class ExecCommand
|
||||||
{
|
{
|
||||||
|
@ -40,6 +42,12 @@
|
||||||
{
|
{
|
||||||
$package = $args['package'] ?? null;
|
$package = $args['package'] ?? null;
|
||||||
$version = $args['exec-version'] ?? 'latest';
|
$version = $args['exec-version'] ?? 'latest';
|
||||||
|
$program_arguments = [];
|
||||||
|
|
||||||
|
if(isset($args['exec-args']))
|
||||||
|
{
|
||||||
|
$program_arguments = Resolver::splitArguments(Main::getRawArgs(), '--exec-args');
|
||||||
|
}
|
||||||
|
|
||||||
if($package === null)
|
if($package === null)
|
||||||
{
|
{
|
||||||
|
@ -58,7 +66,7 @@
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return Runtime::execute($package_name);
|
return Runtime::execute($package_name, $program_arguments);
|
||||||
}
|
}
|
||||||
catch(Exception $e)
|
catch(Exception $e)
|
||||||
{
|
{
|
||||||
|
|
0
src/ncc/CLI/Commands/PackageInspectorCommand.php
Normal file → Executable file
0
src/ncc/CLI/Commands/SetupCommand.php
Normal file → Executable file
0
src/ncc/CLI/HelpMenu.php
Normal file → Executable file
46
src/ncc/CLI/Main.php
Normal file → Executable file
|
@ -50,7 +50,12 @@
|
||||||
private static $args;
|
private static $args;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string|null
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $raw_args;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var LogLevel|null
|
||||||
*/
|
*/
|
||||||
private static $log_level;
|
private static $log_level;
|
||||||
|
|
||||||
|
@ -63,6 +68,7 @@
|
||||||
public static function start(array $argv): int
|
public static function start(array $argv): int
|
||||||
{
|
{
|
||||||
self::$args = Resolver::parseArguments(implode(' ', $argv));
|
self::$args = Resolver::parseArguments(implode(' ', $argv));
|
||||||
|
self::$raw_args = $argv;
|
||||||
|
|
||||||
if(!isset(self::$args['ncc-cli']))
|
if(!isset(self::$args['ncc-cli']))
|
||||||
{
|
{
|
||||||
|
@ -91,30 +97,14 @@
|
||||||
|
|
||||||
if(isset(self::$args['l']) || isset(self::$args['log-level']))
|
if(isset(self::$args['l']) || isset(self::$args['log-level']))
|
||||||
{
|
{
|
||||||
switch(strtolower(self::$args['l'] ?? self::$args['log-level']))
|
self::$log_level = LogLevel::fromOrDefault(strtolower(self::$args['l'] ?? self::$args['log-level']));
|
||||||
{
|
|
||||||
case LogLevel::SILENT:
|
|
||||||
case LogLevel::FATAL:
|
|
||||||
case LogLevel::ERROR:
|
|
||||||
case LogLevel::WARNING:
|
|
||||||
case LogLevel::INFO:
|
|
||||||
case LogLevel::DEBUG:
|
|
||||||
case LogLevel::VERBOSE:
|
|
||||||
self::$log_level = strtolower(self::$args['l'] ?? self::$args['log-level']);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
Console::outWarning('Unknown log level: ' . (self::$args['l'] ?? self::$args['log-level']) . ', using \'info\'');
|
|
||||||
self::$log_level = LogLevel::INFO;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
self::$log_level = LogLevel::INFO;
|
self::$log_level = LogLevel::INFO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Resolver::checkLogLevel(self::$log_level, LogLevel::DEBUG))
|
if(self::$log_level->checkLogLevel(LogLevel::DEBUG))
|
||||||
{
|
{
|
||||||
Console::outDebug('Debug logging enabled');
|
Console::outDebug('Debug logging enabled');
|
||||||
|
|
||||||
|
@ -125,12 +115,12 @@
|
||||||
Console::outDebug(sprintf('args: %s', json_encode(self::$args, JSON_UNESCAPED_SLASHES)));
|
Console::outDebug(sprintf('args: %s', json_encode(self::$args, JSON_UNESCAPED_SLASHES)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(in_array(NccBuildFlags::UNSTABLE, NCC_VERSION_FLAGS, true))
|
if(in_array(NccBuildFlags::UNSTABLE->value, NCC_VERSION_FLAGS, true))
|
||||||
{
|
{
|
||||||
Console::outWarning('This is an unstable build of ncc, expect some features to not work as expected');
|
Console::outWarning('This is an unstable build of ncc, expect some features to not work as expected');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(in_array(NccBuildFlags::BETA, NCC_VERSION_FLAGS, true))
|
if(in_array(NccBuildFlags::BETA->value, NCC_VERSION_FLAGS, true))
|
||||||
{
|
{
|
||||||
Console::outWarning('This is a beta build of ncc, expect some features to not work as expected');
|
Console::outWarning('This is a beta build of ncc, expect some features to not work as expected');
|
||||||
}
|
}
|
||||||
|
@ -230,9 +220,19 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* Returns the raw arguments passed to ncc
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function getLogLevel(): string
|
public static function getRawArgs(): array
|
||||||
|
{
|
||||||
|
return self::$raw_args;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return LogLevel
|
||||||
|
*/
|
||||||
|
public static function getLogLevel(): LogLevel
|
||||||
{
|
{
|
||||||
if(self::$log_level === null)
|
if(self::$log_level === null)
|
||||||
{
|
{
|
||||||
|
|
2
src/ncc/CLI/Management/ConfigMenu.php
Normal file → Executable file
|
@ -101,7 +101,7 @@
|
||||||
|
|
||||||
if(isset($args['v']))
|
if(isset($args['v']))
|
||||||
{
|
{
|
||||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||||
{
|
{
|
||||||
Console::outError('Insufficient permissions, cannot modify configuration values', true, 1);
|
Console::outError('Insufficient permissions, cannot modify configuration values', true, 1);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
4
src/ncc/CLI/Management/CredentialMenu.php
Normal file → Executable file
|
@ -187,7 +187,7 @@
|
||||||
{
|
{
|
||||||
$ResolvedScope = Resolver::resolveScope();
|
$ResolvedScope = Resolver::resolveScope();
|
||||||
|
|
||||||
if($ResolvedScope !== Scopes::SYSTEM)
|
if($ResolvedScope !== Scopes::SYSTEM->value)
|
||||||
{
|
{
|
||||||
Console::outError('Insufficient permissions to add entries');
|
Console::outError('Insufficient permissions to add entries');
|
||||||
}
|
}
|
||||||
|
@ -313,7 +313,7 @@
|
||||||
{
|
{
|
||||||
$ResolvedScope = Resolver::resolveScope();
|
$ResolvedScope = Resolver::resolveScope();
|
||||||
|
|
||||||
if($ResolvedScope !== Scopes::SYSTEM)
|
if($ResolvedScope !== Scopes::SYSTEM->value)
|
||||||
{
|
{
|
||||||
Console::outError('Insufficient permissions to remove entries');
|
Console::outError('Insufficient permissions to remove entries');
|
||||||
}
|
}
|
||||||
|
|
22
src/ncc/CLI/Management/PackageManagerMenu.php
Normal file → Executable file
|
@ -132,7 +132,7 @@
|
||||||
*/
|
*/
|
||||||
private static function installPackage(array $args): int
|
private static function installPackage(array $args): int
|
||||||
{
|
{
|
||||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||||
{
|
{
|
||||||
Console::outError('You cannot install packages in a user scope, please run this command as root', true, 1);
|
Console::outError('You cannot install packages in a user scope, please run this command as root', true, 1);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -155,17 +155,22 @@
|
||||||
|
|
||||||
if(isset($args['reinstall']))
|
if(isset($args['reinstall']))
|
||||||
{
|
{
|
||||||
$options[InstallPackageOptions::REINSTALL] = true;
|
$options[InstallPackageOptions::REINSTALL->value] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($args['prefer-static']) || isset($args['static']))
|
if(isset($args['prefer-static']) || isset($args['static']))
|
||||||
{
|
{
|
||||||
$options[InstallPackageOptions::PREFER_STATIC] = true;
|
$options[InstallPackageOptions::PREFER_STATIC->value] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($args['skip-dependencies']))
|
if(isset($args['skip-dependencies']))
|
||||||
{
|
{
|
||||||
$options[InstallPackageOptions::SKIP_DEPENDENCIES] = true;
|
$options[InstallPackageOptions::SKIP_DEPENDENCIES->value] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($args['build-source']))
|
||||||
|
{
|
||||||
|
$options[InstallPackageOptions::BUILD_SOURCE->value] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($authentication !== null)
|
if($authentication !== null)
|
||||||
|
@ -199,7 +204,7 @@
|
||||||
$authentication_entry = $entry->getPassword();
|
$authentication_entry = $entry->getPassword();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(preg_match(RegexPatterns::REMOTE_PACKAGE, $package) === 1)
|
if(preg_match(RegexPatterns::REMOTE_PACKAGE->value, $package) === 1)
|
||||||
{
|
{
|
||||||
$package_input = RemotePackageInput::fromString($package);
|
$package_input = RemotePackageInput::fromString($package);
|
||||||
|
|
||||||
|
@ -388,7 +393,7 @@
|
||||||
*/
|
*/
|
||||||
private static function uninstallPackage($args): int
|
private static function uninstallPackage($args): int
|
||||||
{
|
{
|
||||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||||
{
|
{
|
||||||
Console::outError('You cannot uninstall packages in a user scope, please run this command as root', true, 1);
|
Console::outError('You cannot uninstall packages in a user scope, please run this command as root', true, 1);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -419,7 +424,7 @@
|
||||||
*/
|
*/
|
||||||
private static function uninstallAllPackages(array $args): int
|
private static function uninstallAllPackages(array $args): int
|
||||||
{
|
{
|
||||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||||
{
|
{
|
||||||
Console::outError('You cannot uninstall all packages in a user scope, please run this command as root', true, 1);
|
Console::outError('You cannot uninstall all packages in a user scope, please run this command as root', true, 1);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -455,7 +460,7 @@
|
||||||
*/
|
*/
|
||||||
private static function fixBrokenPackages(array $args): int
|
private static function fixBrokenPackages(array $args): int
|
||||||
{
|
{
|
||||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||||
{
|
{
|
||||||
Console::outError('You cannot fix broken packages in a user scope, please run this command as root', true, 1);
|
Console::outError('You cannot fix broken packages in a user scope, please run this command as root', true, 1);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -560,6 +565,7 @@
|
||||||
new CliHelpSection(['install', '-p', '--skip-dependencies'], 'Installs a specified ncc package but skips the installation of dependencies'),
|
new CliHelpSection(['install', '-p', '--skip-dependencies'], 'Installs a specified ncc package but skips the installation of dependencies'),
|
||||||
new CliHelpSection(['install', '-p', '--reinstall'], 'Installs a specified ncc package, reinstall if already installed'),
|
new CliHelpSection(['install', '-p', '--reinstall'], 'Installs a specified ncc package, reinstall if already installed'),
|
||||||
new CliHelpSection(['install', '--prefer-static', '--static'], 'Installs a static version of the package from the remote repository if available'),
|
new CliHelpSection(['install', '--prefer-static', '--static'], 'Installs a static version of the package from the remote repository if available'),
|
||||||
|
new CliHelpSection(['install', '--build-source'], 'Forces ncc to build the packages from source rather than trying to use a pre-built binary'),
|
||||||
new CliHelpSection(['uninstall', '--package', '-p'], 'Uninstalls a specified ncc package'),
|
new CliHelpSection(['uninstall', '--package', '-p'], 'Uninstalls a specified ncc package'),
|
||||||
new CliHelpSection(['uninstall', '--package', '-p', '--version', '-v'], 'Uninstalls a specified ncc package version'),
|
new CliHelpSection(['uninstall', '--package', '-p', '--version', '-v'], 'Uninstalls a specified ncc package version'),
|
||||||
new CliHelpSection(['uninstall-all'], 'Uninstalls all packages'),
|
new CliHelpSection(['uninstall-all'], 'Uninstalls all packages'),
|
||||||
|
|
14
src/ncc/CLI/Management/ProjectMenu.php
Normal file → Executable file
|
@ -23,6 +23,7 @@
|
||||||
namespace ncc\CLI\Management;
|
namespace ncc\CLI\Management;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use ncc\Enums\CompilerExtensions;
|
||||||
use ncc\Enums\ProjectTemplates;
|
use ncc\Enums\ProjectTemplates;
|
||||||
use ncc\Enums\Scopes;
|
use ncc\Enums\Scopes;
|
||||||
use ncc\Managers\CredentialManager;
|
use ncc\Managers\CredentialManager;
|
||||||
|
@ -102,7 +103,12 @@
|
||||||
|
|
||||||
if(isset($args['ext']))
|
if(isset($args['ext']))
|
||||||
{
|
{
|
||||||
$compiler_extension = $args['ext'];
|
$compiler_extension = CompilerExtensions::tryFrom($args['ext']);
|
||||||
|
if($compiler_extension === null)
|
||||||
|
{
|
||||||
|
Console::outError('Invalid compiler extension, please specify a valid compiler extension', true, 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -134,7 +140,7 @@
|
||||||
*/
|
*/
|
||||||
private static function installProject(array $args): int
|
private static function installProject(array $args): int
|
||||||
{
|
{
|
||||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||||
{
|
{
|
||||||
Console::outError('You cannot install packages in a user scope, please run this command as root', true, 1);
|
Console::outError('You cannot install packages in a user scope, please run this command as root', true, 1);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -292,9 +298,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
Console::out(PHP_EOL . 'Available Templates:');
|
Console::out(PHP_EOL . 'Available Templates:');
|
||||||
foreach(ProjectTemplates::ALL as $template)
|
foreach(ProjectTemplates::cases() as $template)
|
||||||
{
|
{
|
||||||
Console::out(' ' . $template);
|
Console::out(' ' . $template->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
16
src/ncc/CLI/Management/RepositoryMenu.php
Normal file → Executable file
|
@ -25,6 +25,7 @@
|
||||||
use Exception;
|
use Exception;
|
||||||
use ncc\Enums\ConsoleColors;
|
use ncc\Enums\ConsoleColors;
|
||||||
use ncc\Enums\Scopes;
|
use ncc\Enums\Scopes;
|
||||||
|
use ncc\Enums\Types\RepositoryType;
|
||||||
use ncc\Managers\RepositoryManager;
|
use ncc\Managers\RepositoryManager;
|
||||||
use ncc\Objects\CliHelpSection;
|
use ncc\Objects\CliHelpSection;
|
||||||
use ncc\Objects\RepositoryConfiguration;
|
use ncc\Objects\RepositoryConfiguration;
|
||||||
|
@ -118,7 +119,7 @@
|
||||||
$output = sprintf('%s (%s) [%s]',
|
$output = sprintf('%s (%s) [%s]',
|
||||||
$source->getName(),
|
$source->getName(),
|
||||||
Console::formatColor($source->getHost(), ConsoleColors::GREEN),
|
Console::formatColor($source->getHost(), ConsoleColors::GREEN),
|
||||||
Console::formatColor($source->getType(), ConsoleColors::YELLOW)
|
Console::formatColor($source->getType()->value, ConsoleColors::YELLOW)
|
||||||
);
|
);
|
||||||
|
|
||||||
if(!$source->isSsl())
|
if(!$source->isSsl())
|
||||||
|
@ -141,7 +142,7 @@
|
||||||
*/
|
*/
|
||||||
private static function addEntry(array $args): int
|
private static function addEntry(array $args): int
|
||||||
{
|
{
|
||||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||||
{
|
{
|
||||||
Console::outError('You must be running as root to add a new repository', true, 1);
|
Console::outError('You must be running as root to add a new repository', true, 1);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -164,6 +165,13 @@
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$parsed_type = RepositoryType::tryFrom($type);
|
||||||
|
if($parsed_type === null)
|
||||||
|
{
|
||||||
|
Console::outError(sprintf('Unknown repository type \'%s\'.', $type), true, 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if($host === null)
|
if($host === null)
|
||||||
{
|
{
|
||||||
Console::outError(sprintf('Missing required argument \'%s\'.', 'host'), true, 1);
|
Console::outError(sprintf('Missing required argument \'%s\'.', 'host'), true, 1);
|
||||||
|
@ -172,7 +180,7 @@
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
(new RepositoryManager())->addRepository(new RepositoryConfiguration($name, $host, $type, $ssl));
|
(new RepositoryManager())->addRepository(new RepositoryConfiguration($name, $host, $parsed_type, $ssl));
|
||||||
}
|
}
|
||||||
catch(Exception $e)
|
catch(Exception $e)
|
||||||
{
|
{
|
||||||
|
@ -230,7 +238,7 @@
|
||||||
*/
|
*/
|
||||||
private static function removeEntry(array $args): int
|
private static function removeEntry(array $args): int
|
||||||
{
|
{
|
||||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||||
{
|
{
|
||||||
Console::outError('You must be running as root to remove a repository', true, 1);
|
Console::outError('You must be running as root to remove a repository', true, 1);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
8
src/ncc/Classes/ArchiveExtractor.php
Normal file → Executable file
|
@ -29,6 +29,7 @@
|
||||||
use ncc\Utilities\Console;
|
use ncc\Utilities\Console;
|
||||||
use PharData;
|
use PharData;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
use ValueError;
|
||||||
use ZipArchive;
|
use ZipArchive;
|
||||||
|
|
||||||
class ArchiveExtractor
|
class ArchiveExtractor
|
||||||
|
@ -126,6 +127,13 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
$zip_archive->close();
|
$zip_archive->close();
|
||||||
}
|
}
|
||||||
|
catch(ValueError $e)
|
||||||
|
{
|
||||||
|
Console::outWarning('An error occurred while closing the zip archive, ' . $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
0
src/ncc/Classes/BashExtension/BashRunner.php
Normal file → Executable file
28
src/ncc/Classes/ExecutionUnitRunner.php
Normal file → Executable file
|
@ -31,6 +31,7 @@
|
||||||
use ncc\Classes\PhpExtension\PhpRunner;
|
use ncc\Classes\PhpExtension\PhpRunner;
|
||||||
use ncc\Enums\Runners;
|
use ncc\Enums\Runners;
|
||||||
use ncc\Exceptions\ConfigurationException;
|
use ncc\Exceptions\ConfigurationException;
|
||||||
|
use ncc\Exceptions\IntegrityException;
|
||||||
use ncc\Exceptions\IOException;
|
use ncc\Exceptions\IOException;
|
||||||
use ncc\Exceptions\NotSupportedException;
|
use ncc\Exceptions\NotSupportedException;
|
||||||
use ncc\Exceptions\OperationException;
|
use ncc\Exceptions\OperationException;
|
||||||
|
@ -54,11 +55,11 @@
|
||||||
{
|
{
|
||||||
$bin = match($unit->getExecutionPolicy()->getRunner())
|
$bin = match($unit->getExecutionPolicy()->getRunner())
|
||||||
{
|
{
|
||||||
Runners::PHP => (new ExecutableFinder())->find('php'),
|
Runners::PHP->value => (new ExecutableFinder())->find('php'),
|
||||||
Runners::BASH => (new ExecutableFinder())->find('bash'),
|
Runners::BASH->value => (new ExecutableFinder())->find('bash'),
|
||||||
Runners::PYTHON => (new ExecutableFinder())->find('python'),
|
Runners::PYTHON->value => (new ExecutableFinder())->find('python'),
|
||||||
Runners::LUA => (new ExecutableFinder())->find('lua'),
|
Runners::LUA->value => (new ExecutableFinder())->find('lua'),
|
||||||
Runners::PERL => (new ExecutableFinder())->find('perl'),
|
Runners::PERL->value => (new ExecutableFinder())->find('perl'),
|
||||||
|
|
||||||
default => throw new NotSupportedException(sprintf('The execution policy %s is not supported because it uses the %s runner', $unit->getExecutionPolicy()->getName(), $unit->getExecutionPolicy()->getRunner()))
|
default => throw new NotSupportedException(sprintf('The execution policy %s is not supported because it uses the %s runner', $unit->getExecutionPolicy()->getName(), $unit->getExecutionPolicy()->getRunner()))
|
||||||
};
|
};
|
||||||
|
@ -76,11 +77,19 @@
|
||||||
{
|
{
|
||||||
$process->setTimeout($unit->getExecutionPolicy()->getExecute()->getTimeout());
|
$process->setTimeout($unit->getExecutionPolicy()->getExecute()->getTimeout());
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$process->setTimeout(null);
|
||||||
|
}
|
||||||
|
|
||||||
if($unit->getExecutionPolicy()->getExecute()->getIdleTimeout() !== null)
|
if($unit->getExecutionPolicy()->getExecute()->getIdleTimeout() !== null)
|
||||||
{
|
{
|
||||||
$process->setIdleTimeout($unit->getExecutionPolicy()->getExecute()->getIdleTimeout());
|
$process->setIdleTimeout($unit->getExecutionPolicy()->getExecute()->getIdleTimeout());
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$process->setIdleTimeout(null);
|
||||||
|
}
|
||||||
|
|
||||||
return $process;
|
return $process;
|
||||||
}
|
}
|
||||||
|
@ -109,8 +118,8 @@
|
||||||
$execution_unit = ExecutionUnit::fromArray(ZiProto::decode(IO::fread($unit_path)));
|
$execution_unit = ExecutionUnit::fromArray(ZiProto::decode(IO::fread($unit_path)));
|
||||||
return match ($execution_unit->getExecutionPolicy()->getRunner())
|
return match ($execution_unit->getExecutionPolicy()->getRunner())
|
||||||
{
|
{
|
||||||
Runners::PHP => PhpRunner::executeUnit($execution_unit, $args),
|
Runners::PHP->value => PhpRunner::executeUnit($execution_unit, $args),
|
||||||
Runners::BASH => BashRunner::executeUnit($execution_unit, $args),
|
Runners::BASH->value => BashRunner::executeUnit($execution_unit, $args),
|
||||||
default => throw new NotSupportedException(sprintf('The execution policy %s is not supported because it uses the %s runner', $execution_unit->getExecutionPolicy()->getName(), $execution_unit->getExecutionPolicy()->getRunner())),
|
default => throw new NotSupportedException(sprintf('The execution policy %s is not supported because it uses the %s runner', $execution_unit->getExecutionPolicy()->getName(), $execution_unit->getExecutionPolicy()->getRunner())),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -129,6 +138,7 @@
|
||||||
* @return int
|
* @return int
|
||||||
* @throws ConfigurationException
|
* @throws ConfigurationException
|
||||||
* @throws OperationException
|
* @throws OperationException
|
||||||
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public static function executeFromPackage(PackageReader $package_reader, string $policy_name, array $args=[]): int
|
public static function executeFromPackage(PackageReader $package_reader, string $policy_name, array $args=[]): int
|
||||||
{
|
{
|
||||||
|
@ -138,8 +148,8 @@
|
||||||
{
|
{
|
||||||
return match ($execution_unit->getExecutionPolicy()->getRunner())
|
return match ($execution_unit->getExecutionPolicy()->getRunner())
|
||||||
{
|
{
|
||||||
Runners::PHP => PhpRunner::executeUnit($execution_unit, $args, false),
|
Runners::PHP->value => PhpRunner::executeUnit($execution_unit, $args, false),
|
||||||
Runners::BASH => BashRunner::executeUnit($execution_unit, $args),
|
Runners::BASH->value => BashRunner::executeUnit($execution_unit, $args),
|
||||||
default => throw new NotSupportedException(sprintf('The execution policy %s is not supported because it uses the %s runner', $execution_unit->getExecutionPolicy()->getName(), $execution_unit->getExecutionPolicy()->getRunner())),
|
default => throw new NotSupportedException(sprintf('The execution policy %s is not supported because it uses the %s runner', $execution_unit->getExecutionPolicy()->getName(), $execution_unit->getExecutionPolicy()->getRunner())),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
73
src/ncc/Classes/GiteaExtension/GiteaRepository.php
Normal file → Executable file
|
@ -39,6 +39,7 @@
|
||||||
use ncc\Objects\Vault\Password\AccessToken;
|
use ncc\Objects\Vault\Password\AccessToken;
|
||||||
use ncc\Objects\Vault\Password\UsernamePassword;
|
use ncc\Objects\Vault\Password\UsernamePassword;
|
||||||
use ncc\Utilities\Console;
|
use ncc\Utilities\Console;
|
||||||
|
use ncc\Utilities\Resolver;
|
||||||
use ncc\Utilities\RuntimeCache;
|
use ncc\Utilities\RuntimeCache;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult
|
public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST->value, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -64,7 +65,7 @@
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult
|
public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST->value, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult
|
||||||
{
|
{
|
||||||
return self::getReleasePackage($repository, $vendor, $project, $version, $authentication, $options);
|
return self::getReleasePackage($repository, $vendor, $project, $version, $authentication, $options);
|
||||||
}
|
}
|
||||||
|
@ -97,15 +98,21 @@
|
||||||
'User-Agent: ncc'
|
'User-Agent: ncc'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
if($authentication !== null)
|
if($authentication !== null)
|
||||||
{
|
{
|
||||||
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$resolved_host = Resolver::getResolveOption($endpoint);
|
||||||
|
|
||||||
|
if($resolved_host !== null)
|
||||||
|
{
|
||||||
|
curl_setopt($curl, CURLOPT_RESOLVE, [$resolved_host]);
|
||||||
|
}
|
||||||
|
|
||||||
curl_setopt_array($curl, [
|
curl_setopt_array($curl, [
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET,
|
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET->value,
|
||||||
CURLOPT_HTTPHEADER => $headers
|
CURLOPT_HTTPHEADER => $headers
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -162,7 +169,7 @@
|
||||||
*/
|
*/
|
||||||
private static function getTagArchive(RepositoryConfiguration $repository, string $group, string $project, string $tag, ?AuthenticationInterface $authentication=null): RepositoryResult
|
private static function getTagArchive(RepositoryConfiguration $repository, string $group, string $project, string $tag, ?AuthenticationInterface $authentication=null): RepositoryResult
|
||||||
{
|
{
|
||||||
if($tag === Versions::LATEST)
|
if($tag === Versions::LATEST->value)
|
||||||
{
|
{
|
||||||
$tag = self::getLatestTag($repository, $group, $project, $authentication);
|
$tag = self::getLatestTag($repository, $group, $project, $authentication);
|
||||||
}
|
}
|
||||||
|
@ -186,10 +193,17 @@
|
||||||
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$resolved_host = Resolver::getResolveOption($endpoint);
|
||||||
|
|
||||||
|
if($resolved_host !== null)
|
||||||
|
{
|
||||||
|
curl_setopt($curl, CURLOPT_RESOLVE, [$resolved_host]);
|
||||||
|
}
|
||||||
|
|
||||||
curl_setopt_array($curl, [
|
curl_setopt_array($curl, [
|
||||||
CURLOPT_URL => $endpoint,
|
CURLOPT_URL => $endpoint,
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET,
|
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET->value,
|
||||||
CURLOPT_HTTPHEADER => $headers
|
CURLOPT_HTTPHEADER => $headers
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -198,11 +212,11 @@
|
||||||
|
|
||||||
if(isset($response['zipball_url']))
|
if(isset($response['zipball_url']))
|
||||||
{
|
{
|
||||||
$result = new RepositoryResult($response['zipball_url'], RepositoryResultType::SOURCE, $tag);
|
$result = new RepositoryResult($response['zipball_url'], RepositoryResultType::SOURCE->value, $tag);
|
||||||
}
|
}
|
||||||
elseif(isset($response['tarball_url']))
|
elseif(isset($response['tarball_url']))
|
||||||
{
|
{
|
||||||
$result = new RepositoryResult($response['tarball_url'], RepositoryResultType::SOURCE, $tag);
|
$result = new RepositoryResult($response['tarball_url'], RepositoryResultType::SOURCE->value, $tag);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -246,10 +260,17 @@
|
||||||
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$resolved_host = Resolver::getResolveOption($endpoint);
|
||||||
|
|
||||||
|
if($resolved_host !== null)
|
||||||
|
{
|
||||||
|
curl_setopt($curl, CURLOPT_RESOLVE, [$resolved_host]);
|
||||||
|
}
|
||||||
|
|
||||||
curl_setopt_array($curl, [
|
curl_setopt_array($curl, [
|
||||||
CURLOPT_URL => $endpoint,
|
CURLOPT_URL => $endpoint,
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET,
|
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET->value,
|
||||||
CURLOPT_HTTPHEADER => $headers
|
CURLOPT_HTTPHEADER => $headers
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -307,7 +328,7 @@
|
||||||
private static function getReleasePackage(RepositoryConfiguration $repository, string $group, string $project, string $release, ?AuthenticationInterface $authentication=null, array $options=[]): RepositoryResult
|
private static function getReleasePackage(RepositoryConfiguration $repository, string $group, string $project, string $release, ?AuthenticationInterface $authentication=null, array $options=[]): RepositoryResult
|
||||||
{
|
{
|
||||||
/** @noinspection DuplicatedCode */
|
/** @noinspection DuplicatedCode */
|
||||||
if($release === Versions::LATEST)
|
if($release === Versions::LATEST->value)
|
||||||
{
|
{
|
||||||
$release = self::getLatestRelease($repository, $group, $project, $authentication);
|
$release = self::getLatestRelease($repository, $group, $project, $authentication);
|
||||||
}
|
}
|
||||||
|
@ -337,10 +358,17 @@
|
||||||
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$resolved_host = Resolver::getResolveOption($endpoint);
|
||||||
|
|
||||||
|
if($resolved_host !== null)
|
||||||
|
{
|
||||||
|
curl_setopt($curl, CURLOPT_RESOLVE, [$resolved_host]);
|
||||||
|
}
|
||||||
|
|
||||||
curl_setopt_array($curl, [
|
curl_setopt_array($curl, [
|
||||||
CURLOPT_URL => $endpoint,
|
CURLOPT_URL => $endpoint,
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET,
|
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET->value,
|
||||||
CURLOPT_HTTPHEADER => $headers
|
CURLOPT_HTTPHEADER => $headers
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -355,7 +383,7 @@
|
||||||
$release, $group, $project));
|
$release, $group, $project));
|
||||||
}
|
}
|
||||||
|
|
||||||
$static_preferred = isset($options[InstallPackageOptions::PREFER_STATIC]);
|
$static_preferred = isset($options[InstallPackageOptions::PREFER_STATIC->value]);
|
||||||
$preferred_asset = null;
|
$preferred_asset = null;
|
||||||
$fallback_asset = null;
|
$fallback_asset = null;
|
||||||
|
|
||||||
|
@ -379,7 +407,7 @@
|
||||||
|
|
||||||
if($asset_url)
|
if($asset_url)
|
||||||
{
|
{
|
||||||
$result = new RepositoryResult($asset_url, RepositoryResultType::PACKAGE, $release);
|
$result = new RepositoryResult($asset_url, RepositoryResultType::PACKAGE->value, $release);
|
||||||
|
|
||||||
RuntimeCache::set($endpoint, $result);
|
RuntimeCache::set($endpoint, $result);
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -409,7 +437,7 @@
|
||||||
private static function getReleaseArchive(RepositoryConfiguration $repository, string $group, string $project, string $release, ?AuthenticationInterface $authentication=null): RepositoryResult
|
private static function getReleaseArchive(RepositoryConfiguration $repository, string $group, string $project, string $release, ?AuthenticationInterface $authentication=null): RepositoryResult
|
||||||
{
|
{
|
||||||
/** @noinspection DuplicatedCode */
|
/** @noinspection DuplicatedCode */
|
||||||
if ($release === Versions::LATEST)
|
if ($release === Versions::LATEST->value)
|
||||||
{
|
{
|
||||||
$release = self::getLatestRelease($repository, $group, $project, $authentication);
|
$release = self::getLatestRelease($repository, $group, $project, $authentication);
|
||||||
}
|
}
|
||||||
|
@ -433,10 +461,17 @@
|
||||||
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$resolved_host = Resolver::getResolveOption($endpoint);
|
||||||
|
|
||||||
|
if($resolved_host !== null)
|
||||||
|
{
|
||||||
|
curl_setopt($curl, CURLOPT_RESOLVE, [$resolved_host]);
|
||||||
|
}
|
||||||
|
|
||||||
curl_setopt_array($curl, [
|
curl_setopt_array($curl, [
|
||||||
CURLOPT_URL => $endpoint,
|
CURLOPT_URL => $endpoint,
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET,
|
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET->value,
|
||||||
CURLOPT_HTTPHEADER => $headers
|
CURLOPT_HTTPHEADER => $headers
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -445,11 +480,11 @@
|
||||||
|
|
||||||
if(isset($response['zipball_url']))
|
if(isset($response['zipball_url']))
|
||||||
{
|
{
|
||||||
$results = new RepositoryResult($response['zipball_url'], RepositoryResultType::SOURCE, $release);
|
$results = new RepositoryResult($response['zipball_url'], RepositoryResultType::SOURCE->value, $release);
|
||||||
}
|
}
|
||||||
elseif(isset($response['tarball_url']))
|
elseif(isset($response['tarball_url']))
|
||||||
{
|
{
|
||||||
$results = new RepositoryResult($response['tarball_url'], RepositoryResultType::SOURCE, $release);
|
$results = new RepositoryResult($response['tarball_url'], RepositoryResultType::SOURCE->value, $release);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -480,7 +515,7 @@
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new AuthenticationException(sprintf('Invalid authentication type for Access Token, got %s instead', $authentication->getAuthenticationType()));
|
throw new AuthenticationException(sprintf('Invalid authentication type for Access Token, got %s instead', $authentication->getAuthenticationType()->value));
|
||||||
|
|
||||||
case AuthenticationType::USERNAME_PASSWORD:
|
case AuthenticationType::USERNAME_PASSWORD:
|
||||||
if($authentication instanceof UsernamePassword)
|
if($authentication instanceof UsernamePassword)
|
||||||
|
@ -489,7 +524,7 @@
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new AuthenticationException(sprintf('Invalid authentication type for Username/Password, got %s instead', $authentication->getAuthenticationType()));
|
throw new AuthenticationException(sprintf('Invalid authentication type for Username/Password, got %s instead', $authentication->getAuthenticationType()->value));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $headers;
|
return $headers;
|
||||||
|
|
34
src/ncc/Classes/GithubExtension/GithubRepository.php
Normal file → Executable file
|
@ -47,7 +47,7 @@
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult
|
public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST->value, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -64,7 +64,7 @@
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version = Versions::LATEST, ?AuthenticationType $authentication = null, array $options=[]): RepositoryResult
|
public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version = Versions::LATEST->value, ?AuthenticationType $authentication = null, array $options=[]): RepositoryResult
|
||||||
{
|
{
|
||||||
return self::getReleasePackage($repository, $vendor, $project, $version, $authentication, $options);
|
return self::getReleasePackage($repository, $vendor, $project, $version, $authentication, $options);
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@
|
||||||
|
|
||||||
curl_setopt_array($curl, [
|
curl_setopt_array($curl, [
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET,
|
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET->value,
|
||||||
CURLOPT_HTTPHEADER => $headers
|
CURLOPT_HTTPHEADER => $headers
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@
|
||||||
*/
|
*/
|
||||||
private static function getTagArchive(RepositoryConfiguration $repository, string $group, string $project, string $tag, ?AuthenticationInterface $authentication = null): RepositoryResult
|
private static function getTagArchive(RepositoryConfiguration $repository, string $group, string $project, string $tag, ?AuthenticationInterface $authentication = null): RepositoryResult
|
||||||
{
|
{
|
||||||
if($tag === Versions::LATEST)
|
if($tag === Versions::LATEST->value)
|
||||||
{
|
{
|
||||||
$tag = self::getLatestTag($repository, $group, $project, $authentication);
|
$tag = self::getLatestTag($repository, $group, $project, $authentication);
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,7 @@
|
||||||
curl_setopt_array($curl, [
|
curl_setopt_array($curl, [
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_NOBODY => true,
|
CURLOPT_NOBODY => true,
|
||||||
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET,
|
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET->value,
|
||||||
CURLOPT_HTTPHEADER => $headers,
|
CURLOPT_HTTPHEADER => $headers,
|
||||||
CURLOPT_FOLLOWLOCATION => true
|
CURLOPT_FOLLOWLOCATION => true
|
||||||
]);
|
]);
|
||||||
|
@ -207,7 +207,7 @@
|
||||||
throw new NetworkException(sprintf('Server responded with HTTP code %s when getting tag archive for %s/%s/%s', $http_code, $group, $project, $tag));
|
throw new NetworkException(sprintf('Server responded with HTTP code %s when getting tag archive for %s/%s/%s', $http_code, $group, $project, $tag));
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = new RepositoryResult(curl_getinfo($curl, CURLINFO_EFFECTIVE_URL), RepositoryResultType::SOURCE, $tag);
|
$result = new RepositoryResult(curl_getinfo($curl, CURLINFO_EFFECTIVE_URL), RepositoryResultType::SOURCE->value, $tag);
|
||||||
curl_close($curl);
|
curl_close($curl);
|
||||||
RuntimeCache::set($endpoint, $result);
|
RuntimeCache::set($endpoint, $result);
|
||||||
|
|
||||||
|
@ -249,7 +249,7 @@
|
||||||
|
|
||||||
curl_setopt_array($curl, [
|
curl_setopt_array($curl, [
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET,
|
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET->value,
|
||||||
CURLOPT_HTTPHEADER => $headers
|
CURLOPT_HTTPHEADER => $headers
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -307,7 +307,7 @@
|
||||||
private static function getReleasePackage(RepositoryConfiguration $repository, string $group, string $project, string $release, ?AuthenticationInterface $authentication=null, array $options=[]): RepositoryResult
|
private static function getReleasePackage(RepositoryConfiguration $repository, string $group, string $project, string $release, ?AuthenticationInterface $authentication=null, array $options=[]): RepositoryResult
|
||||||
{
|
{
|
||||||
/** @noinspection DuplicatedCode */
|
/** @noinspection DuplicatedCode */
|
||||||
if($release === Versions::LATEST)
|
if($release === Versions::LATEST->value)
|
||||||
{
|
{
|
||||||
$release = self::getLatestRelease($repository, $group, $project, $authentication);
|
$release = self::getLatestRelease($repository, $group, $project, $authentication);
|
||||||
}
|
}
|
||||||
|
@ -331,7 +331,7 @@
|
||||||
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_setopt_array($curl, [CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => HttpRequestType::GET, CURLOPT_HTTPHEADER => $headers]);
|
curl_setopt_array($curl, [CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => HttpRequestType::GET->value, CURLOPT_HTTPHEADER => $headers]);
|
||||||
|
|
||||||
Console::outDebug(sprintf('Fetching release package for %s/%s/%s from %s', $group, $project, $release, $endpoint));
|
Console::outDebug(sprintf('Fetching release package for %s/%s/%s from %s', $group, $project, $release, $endpoint));
|
||||||
$response = self::processHttpResponse($curl, $group, $project);
|
$response = self::processHttpResponse($curl, $group, $project);
|
||||||
|
@ -341,7 +341,7 @@
|
||||||
throw new NetworkException(sprintf('Failed to get release package for %s/%s/%s: No assets found', $group, $project, $release));
|
throw new NetworkException(sprintf('Failed to get release package for %s/%s/%s: No assets found', $group, $project, $release));
|
||||||
}
|
}
|
||||||
|
|
||||||
$static_preferred = isset($options[InstallPackageOptions::PREFER_STATIC]);
|
$static_preferred = isset($options[InstallPackageOptions::PREFER_STATIC->value]);
|
||||||
$preferred_asset = null;
|
$preferred_asset = null;
|
||||||
$fallback_asset = null;
|
$fallback_asset = null;
|
||||||
|
|
||||||
|
@ -363,7 +363,7 @@
|
||||||
{
|
{
|
||||||
$asset_url = $target_asset['browser_download_url'];
|
$asset_url = $target_asset['browser_download_url'];
|
||||||
|
|
||||||
$result = new RepositoryResult($asset_url, RepositoryResultType::PACKAGE, $release);
|
$result = new RepositoryResult($asset_url, RepositoryResultType::PACKAGE->value, $release);
|
||||||
|
|
||||||
RuntimeCache::set($endpoint, $result);
|
RuntimeCache::set($endpoint, $result);
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -389,7 +389,7 @@
|
||||||
private static function getReleaseArchive(RepositoryConfiguration $repository, string $group, string $project, string $release, ?AuthenticationInterface $authentication = null): RepositoryResult
|
private static function getReleaseArchive(RepositoryConfiguration $repository, string $group, string $project, string $release, ?AuthenticationInterface $authentication = null): RepositoryResult
|
||||||
{
|
{
|
||||||
/** @noinspection DuplicatedCode */
|
/** @noinspection DuplicatedCode */
|
||||||
if($release === Versions::LATEST)
|
if($release === Versions::LATEST->value)
|
||||||
{
|
{
|
||||||
$release = self::getLatestRelease($repository, $group, $project, $authentication);
|
$release = self::getLatestRelease($repository, $group, $project, $authentication);
|
||||||
}
|
}
|
||||||
|
@ -415,7 +415,7 @@
|
||||||
|
|
||||||
curl_setopt_array($curl, [
|
curl_setopt_array($curl, [
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET,
|
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET->value,
|
||||||
CURLOPT_HTTPHEADER => $headers
|
CURLOPT_HTTPHEADER => $headers
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -425,11 +425,11 @@
|
||||||
|
|
||||||
if(isset($response['zipball_url']))
|
if(isset($response['zipball_url']))
|
||||||
{
|
{
|
||||||
$result = new RepositoryResult($response['zipball_url'], RepositoryResultType::SOURCE, $release);
|
$result = new RepositoryResult($response['zipball_url'], RepositoryResultType::SOURCE->value, $release);
|
||||||
}
|
}
|
||||||
elseif(isset($response['tarball_url']))
|
elseif(isset($response['tarball_url']))
|
||||||
{
|
{
|
||||||
$result = new RepositoryResult($response['tarball_url'], RepositoryResultType::SOURCE, $release);
|
$result = new RepositoryResult($response['tarball_url'], RepositoryResultType::SOURCE->value, $release);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -459,7 +459,7 @@
|
||||||
$headers[] = 'Authorization: Bearer ' . $authentication->getAccessToken();
|
$headers[] = 'Authorization: Bearer ' . $authentication->getAccessToken();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
throw new AuthenticationException(sprintf('Invalid authentication type for Access Token, got %s instead', $authentication->getAuthenticationType()));
|
throw new AuthenticationException(sprintf('Invalid authentication type for Access Token, got %s instead', $authentication->getAuthenticationType()->value));
|
||||||
|
|
||||||
case AuthenticationType::USERNAME_PASSWORD:
|
case AuthenticationType::USERNAME_PASSWORD:
|
||||||
if($authentication instanceof UsernamePassword)
|
if($authentication instanceof UsernamePassword)
|
||||||
|
@ -468,7 +468,7 @@
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new AuthenticationException(sprintf('Invalid authentication type for Username/Password, got %s instead', $authentication->getAuthenticationType()));
|
throw new AuthenticationException(sprintf('Invalid authentication type for Username/Password, got %s instead', $authentication->getAuthenticationType()->value));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $headers;
|
return $headers;
|
||||||
|
|
74
src/ncc/Classes/GitlabExtension/GitlabRepository.php
Normal file → Executable file
|
@ -39,6 +39,7 @@
|
||||||
use ncc\Objects\Vault\Password\AccessToken;
|
use ncc\Objects\Vault\Password\AccessToken;
|
||||||
use ncc\Objects\Vault\Password\UsernamePassword;
|
use ncc\Objects\Vault\Password\UsernamePassword;
|
||||||
use ncc\Utilities\Console;
|
use ncc\Utilities\Console;
|
||||||
|
use ncc\Utilities\Resolver;
|
||||||
use ncc\Utilities\RuntimeCache;
|
use ncc\Utilities\RuntimeCache;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult
|
public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST->value, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -64,7 +65,7 @@
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult
|
public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST->value, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult
|
||||||
{
|
{
|
||||||
return self::getReleasePackage($repository, $vendor, $project, $version, $authentication, $options);
|
return self::getReleasePackage($repository, $vendor, $project, $version, $authentication, $options);
|
||||||
}
|
}
|
||||||
|
@ -103,10 +104,17 @@
|
||||||
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$resolved_host = Resolver::getResolveOption($endpoint);
|
||||||
|
|
||||||
|
if($resolved_host !== null)
|
||||||
|
{
|
||||||
|
curl_setopt($curl, CURLOPT_RESOLVE, [$resolved_host]);
|
||||||
|
}
|
||||||
|
|
||||||
curl_setopt_array($curl, [
|
curl_setopt_array($curl, [
|
||||||
CURLOPT_URL => $endpoint,
|
CURLOPT_URL => $endpoint,
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET,
|
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET->value,
|
||||||
CURLOPT_HTTPHEADER => $headers
|
CURLOPT_HTTPHEADER => $headers
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -164,7 +172,7 @@
|
||||||
*/
|
*/
|
||||||
private static function getTagArchive(RepositoryConfiguration $repository, string $group, string $project, string $tag, ?AuthenticationInterface $authentication=null): RepositoryResult
|
private static function getTagArchive(RepositoryConfiguration $repository, string $group, string $project, string $tag, ?AuthenticationInterface $authentication=null): RepositoryResult
|
||||||
{
|
{
|
||||||
if($tag === Versions::LATEST)
|
if($tag === Versions::LATEST->value)
|
||||||
{
|
{
|
||||||
$tag = self::getLatestTag($repository, $group, $project, $authentication);
|
$tag = self::getLatestTag($repository, $group, $project, $authentication);
|
||||||
}
|
}
|
||||||
|
@ -187,10 +195,17 @@
|
||||||
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$resolved_host = Resolver::getResolveOption($endpoint);
|
||||||
|
|
||||||
|
if($resolved_host !== null)
|
||||||
|
{
|
||||||
|
curl_setopt($curl, CURLOPT_RESOLVE, [$resolved_host]);
|
||||||
|
}
|
||||||
|
|
||||||
curl_setopt_array($curl, [
|
curl_setopt_array($curl, [
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_NOBODY => true,
|
CURLOPT_NOBODY => true,
|
||||||
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET,
|
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET->value,
|
||||||
CURLOPT_HTTPHEADER => $headers,
|
CURLOPT_HTTPHEADER => $headers,
|
||||||
CURLOPT_FOLLOWLOCATION => true
|
CURLOPT_FOLLOWLOCATION => true
|
||||||
]);
|
]);
|
||||||
|
@ -210,7 +225,7 @@
|
||||||
throw new NetworkException(sprintf('Server responded with HTTP code %s when getting tag archive for %s/%s/%s', $http_code, $group, $project, $tag));
|
throw new NetworkException(sprintf('Server responded with HTTP code %s when getting tag archive for %s/%s/%s', $http_code, $group, $project, $tag));
|
||||||
}
|
}
|
||||||
|
|
||||||
$results = new RepositoryResult(curl_getinfo($curl, CURLINFO_EFFECTIVE_URL), RepositoryResultType::SOURCE, $tag);
|
$results = new RepositoryResult(curl_getinfo($curl, CURLINFO_EFFECTIVE_URL), RepositoryResultType::SOURCE->value, $tag);
|
||||||
RuntimeCache::set($endpoint, $results);
|
RuntimeCache::set($endpoint, $results);
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
|
@ -250,9 +265,16 @@
|
||||||
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$resolved_host = Resolver::getResolveOption($endpoint);
|
||||||
|
|
||||||
|
if($resolved_host !== null)
|
||||||
|
{
|
||||||
|
curl_setopt($curl, CURLOPT_RESOLVE, [$resolved_host]);
|
||||||
|
}
|
||||||
|
|
||||||
curl_setopt_array($curl, [
|
curl_setopt_array($curl, [
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET,
|
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET->value,
|
||||||
CURLOPT_HTTPHEADER => $headers
|
CURLOPT_HTTPHEADER => $headers
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -308,7 +330,7 @@
|
||||||
*/
|
*/
|
||||||
private static function getReleasePackage(RepositoryConfiguration $repository, string $group, string $project, string $release, ?AuthenticationInterface $authentication=null, array $options=[]): RepositoryResult
|
private static function getReleasePackage(RepositoryConfiguration $repository, string $group, string $project, string $release, ?AuthenticationInterface $authentication=null, array $options=[]): RepositoryResult
|
||||||
{
|
{
|
||||||
if($release === Versions::LATEST)
|
if($release === Versions::LATEST->value)
|
||||||
{
|
{
|
||||||
$release = self::getLatestRelease($repository, $group, $project, $authentication);
|
$release = self::getLatestRelease($repository, $group, $project, $authentication);
|
||||||
}
|
}
|
||||||
|
@ -333,14 +355,21 @@
|
||||||
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$resolved_host = Resolver::getResolveOption($endpoint);
|
||||||
|
|
||||||
|
if($resolved_host !== null)
|
||||||
|
{
|
||||||
|
curl_setopt($curl, CURLOPT_RESOLVE, [$resolved_host]);
|
||||||
|
}
|
||||||
|
|
||||||
curl_setopt_array($curl, [
|
curl_setopt_array($curl, [
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET,
|
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET->value,
|
||||||
CURLOPT_HTTPHEADER => $headers
|
CURLOPT_HTTPHEADER => $headers
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response = self::processHttpResponse($curl, $group, $project);
|
$response = self::processHttpResponse($curl, $group, $project);
|
||||||
$static_preferred = isset($options[InstallPackageOptions::PREFER_STATIC]);
|
$static_preferred = isset($options[InstallPackageOptions::PREFER_STATIC->value]);
|
||||||
$preferred_asset = null;
|
$preferred_asset = null;
|
||||||
$fallback_asset = null;
|
$fallback_asset = null;
|
||||||
|
|
||||||
|
@ -364,7 +393,7 @@
|
||||||
|
|
||||||
if ($asset_url)
|
if ($asset_url)
|
||||||
{
|
{
|
||||||
$result = new RepositoryResult($asset_url, RepositoryResultType::PACKAGE, $release);
|
$result = new RepositoryResult($asset_url, RepositoryResultType::PACKAGE->value, $release);
|
||||||
|
|
||||||
RuntimeCache::set($endpoint, $result);
|
RuntimeCache::set($endpoint, $result);
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -393,7 +422,7 @@
|
||||||
private static function getReleaseArchive(RepositoryConfiguration $repository, string $group, string $project, string $release, ?AuthenticationInterface $authentication=null): RepositoryResult
|
private static function getReleaseArchive(RepositoryConfiguration $repository, string $group, string $project, string $release, ?AuthenticationInterface $authentication=null): RepositoryResult
|
||||||
{
|
{
|
||||||
/** @noinspection DuplicatedCode */
|
/** @noinspection DuplicatedCode */
|
||||||
if($release === Versions::LATEST)
|
if($release === Versions::LATEST->value)
|
||||||
{
|
{
|
||||||
$release = self::getLatestRelease($repository, $group, $project, $authentication);
|
$release = self::getLatestRelease($repository, $group, $project, $authentication);
|
||||||
}
|
}
|
||||||
|
@ -418,9 +447,16 @@
|
||||||
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
$headers = self::injectAuthentication($authentication, $curl, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$resolved_host = Resolver::getResolveOption($endpoint);
|
||||||
|
|
||||||
|
if($resolved_host !== null)
|
||||||
|
{
|
||||||
|
curl_setopt($curl, CURLOPT_RESOLVE, [$resolved_host]);
|
||||||
|
}
|
||||||
|
|
||||||
curl_setopt_array($curl, [
|
curl_setopt_array($curl, [
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET,
|
CURLOPT_CUSTOMREQUEST => HttpRequestType::GET->value,
|
||||||
CURLOPT_HTTPHEADER => $headers
|
CURLOPT_HTTPHEADER => $headers
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -440,11 +476,11 @@
|
||||||
|
|
||||||
if($asset['format'] === 'zip')
|
if($asset['format'] === 'zip')
|
||||||
{
|
{
|
||||||
$results = new RepositoryResult($asset['url'], RepositoryResultType::SOURCE, $release);
|
$results = new RepositoryResult($asset['url'], RepositoryResultType::SOURCE->value, $release);
|
||||||
}
|
}
|
||||||
elseif($asset['format'] === 'tar')
|
elseif($asset['format'] === 'tar')
|
||||||
{
|
{
|
||||||
$results = new RepositoryResult($asset['url'], RepositoryResultType::SOURCE, $release);
|
$results = new RepositoryResult($asset['url'], RepositoryResultType::SOURCE->value, $release);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -471,23 +507,23 @@
|
||||||
{
|
{
|
||||||
switch($authentication->getAuthenticationType())
|
switch($authentication->getAuthenticationType())
|
||||||
{
|
{
|
||||||
case AuthenticationType::ACCESS_TOKEN:
|
case AuthenticationType::ACCESS_TOKEN->value:
|
||||||
if($authentication instanceof AccessToken)
|
if($authentication instanceof AccessToken)
|
||||||
{
|
{
|
||||||
$headers[] = 'Private-Token: ' . $authentication->getAccessToken();
|
$headers[] = 'Private-Token: ' . $authentication->getAccessToken();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new AuthenticationException(sprintf('Invalid authentication type for Access Token, got %s instead', $authentication->getAuthenticationType()));
|
throw new AuthenticationException(sprintf('Invalid authentication type for Access Token, got %s instead', $authentication->getAuthenticationType()->value));
|
||||||
|
|
||||||
case AuthenticationType::USERNAME_PASSWORD:
|
case AuthenticationType::USERNAME_PASSWORD->value:
|
||||||
if($authentication instanceof UsernamePassword)
|
if($authentication instanceof UsernamePassword)
|
||||||
{
|
{
|
||||||
curl_setopt($curl, CURLOPT_USERPWD, $authentication->getUsername() . ':' . $authentication->getPassword());
|
curl_setopt($curl, CURLOPT_USERPWD, $authentication->getUsername() . ':' . $authentication->getPassword());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new AuthenticationException(sprintf('Invalid authentication type for Username/Password, got %s instead', $authentication->getAuthenticationType()));
|
throw new AuthenticationException(sprintf('Invalid authentication type for Username/Password, got %s instead', $authentication->getAuthenticationType()->value));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $headers;
|
return $headers;
|
||||||
|
|
0
src/ncc/Classes/LuaExtension/LuaRunner.php
Normal file → Executable file
167
src/ncc/Classes/NccExtension/ConstantCompiler.php
Normal file → Executable file
|
@ -22,8 +22,10 @@
|
||||||
|
|
||||||
namespace ncc\Classes\NccExtension;
|
namespace ncc\Classes\NccExtension;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
use ncc\Enums\SpecialConstants\BuildConstants;
|
use ncc\Enums\SpecialConstants\BuildConstants;
|
||||||
use ncc\Enums\SpecialConstants\DateTimeConstants;
|
use ncc\Enums\SpecialConstants\DateTimeConstants;
|
||||||
|
use ncc\Enums\SpecialConstants\GeneralConstants;
|
||||||
use ncc\Enums\SpecialConstants\InstallConstants;
|
use ncc\Enums\SpecialConstants\InstallConstants;
|
||||||
use ncc\Enums\SpecialConstants\AssemblyConstants;
|
use ncc\Enums\SpecialConstants\AssemblyConstants;
|
||||||
use ncc\Enums\SpecialConstants\RuntimeConstants;
|
use ncc\Enums\SpecialConstants\RuntimeConstants;
|
||||||
|
@ -47,6 +49,67 @@
|
||||||
$input = self::compileBuildConstants($input);
|
$input = self::compileBuildConstants($input);
|
||||||
$input = self::compileDateTimeConstants($input, time());
|
$input = self::compileDateTimeConstants($input, time());
|
||||||
$input = self::compileRuntimeConstants($input);
|
$input = self::compileRuntimeConstants($input);
|
||||||
|
$input = self::compileGeneralConstants($input, $project_configuration);
|
||||||
|
|
||||||
|
return $input;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compiles general constants from the given input string based on the provided project configuration.
|
||||||
|
*
|
||||||
|
* @param string|null $input The input string containing constants to be compiled.
|
||||||
|
* @param ProjectConfiguration $project_configuration The project configuration used to resolve constants.
|
||||||
|
* @return string|null The input string with constants replaced, or null if the input was null.
|
||||||
|
*/
|
||||||
|
public static function compileGeneralConstants(?string $input, ProjectConfiguration $project_configuration): ?string
|
||||||
|
{
|
||||||
|
if ($input === null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace %DEFAULT_BUILD_CONFIGURATION%
|
||||||
|
$input = str_replace(
|
||||||
|
[
|
||||||
|
GeneralConstants::DEFAULT_BUILD_CONFIGURATION->value
|
||||||
|
],
|
||||||
|
[
|
||||||
|
$project_configuration->getBuild()->getDefaultConfiguration()
|
||||||
|
],
|
||||||
|
$input
|
||||||
|
);
|
||||||
|
|
||||||
|
if (str_starts_with($input, GeneralConstants::BUILD_OUTPUT_PATH->value))
|
||||||
|
{
|
||||||
|
$build_name = null;
|
||||||
|
if (preg_match('/' . preg_quote(GeneralConstants::BUILD_OUTPUT_PATH->value, '/') . ':(\S+)/', $input, $matches))
|
||||||
|
{
|
||||||
|
$build_name = $matches[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($build_name === null)
|
||||||
|
{
|
||||||
|
Console::outWarning(sprintf("Cannot compile constant %s because it's not valid, usage: %%CONSTANT%%:<name>", $input));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$output_path = $project_configuration->getBuild()->getBuildConfiguration($build_name)->getOutput();
|
||||||
|
$input = preg_replace(
|
||||||
|
'/' . preg_quote(GeneralConstants::BUILD_OUTPUT_PATH->value, '/') . ':\S+/',
|
||||||
|
$output_path,
|
||||||
|
$input,
|
||||||
|
1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (InvalidArgumentException $e)
|
||||||
|
{
|
||||||
|
Console::outError(sprintf("Cannot compile constant %s because it does not point to an existing build configuration name", $input));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $input;
|
return $input;
|
||||||
}
|
}
|
||||||
|
@ -67,10 +130,10 @@
|
||||||
|
|
||||||
$input = str_replace(
|
$input = str_replace(
|
||||||
[
|
[
|
||||||
AssemblyConstants::ASSEMBLY_NAME,
|
AssemblyConstants::ASSEMBLY_NAME->value,
|
||||||
AssemblyConstants::ASSEMBLY_PACKAGE,
|
AssemblyConstants::ASSEMBLY_PACKAGE->value,
|
||||||
AssemblyConstants::ASSEMBLY_VERSION,
|
AssemblyConstants::ASSEMBLY_VERSION->value,
|
||||||
AssemblyConstants::ASSEMBLY_UID
|
AssemblyConstants::ASSEMBLY_UID->value,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
$assembly->getName(),
|
$assembly->getName(),
|
||||||
|
@ -81,27 +144,27 @@
|
||||||
|
|
||||||
if($assembly->getDescription() !== null)
|
if($assembly->getDescription() !== null)
|
||||||
{
|
{
|
||||||
$input = str_replace(AssemblyConstants::ASSEMBLY_DESCRIPTION, $assembly->getDescription(), $input);
|
$input = str_replace(AssemblyConstants::ASSEMBLY_DESCRIPTION->value, $assembly->getDescription(), $input);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($assembly->getCompany() !== null)
|
if($assembly->getCompany() !== null)
|
||||||
{
|
{
|
||||||
$input = str_replace(AssemblyConstants::ASSEMBLY_COMPANY, $assembly->getCompany(), $input);
|
$input = str_replace(AssemblyConstants::ASSEMBLY_COMPANY->value, $assembly->getCompany(), $input);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($assembly->getProduct() !== null)
|
if($assembly->getProduct() !== null)
|
||||||
{
|
{
|
||||||
$input = str_replace(AssemblyConstants::ASSEMBLY_PRODUCT, $assembly->getProduct(), $input);
|
$input = str_replace(AssemblyConstants::ASSEMBLY_PRODUCT->value, $assembly->getProduct(), $input);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($assembly->getCopyright() !== null)
|
if($assembly->getCopyright() !== null)
|
||||||
{
|
{
|
||||||
$input = str_replace(AssemblyConstants::ASSEMBLY_COPYRIGHT, $assembly->getCopyright(), $input);
|
$input = str_replace(AssemblyConstants::ASSEMBLY_COPYRIGHT->value, $assembly->getCopyright(), $input);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($assembly->getTrademark() !== null)
|
if($assembly->getTrademark() !== null)
|
||||||
{
|
{
|
||||||
$input = str_replace(AssemblyConstants::ASSEMBLY_TRADEMARK, $assembly->getTrademark(), $input);
|
$input = str_replace(AssemblyConstants::ASSEMBLY_TRADEMARK->value, $assembly->getTrademark(), $input);
|
||||||
}
|
}
|
||||||
return $input;
|
return $input;
|
||||||
}
|
}
|
||||||
|
@ -121,10 +184,10 @@
|
||||||
|
|
||||||
return str_replace(
|
return str_replace(
|
||||||
[
|
[
|
||||||
BuildConstants::COMPILE_TIMESTAMP,
|
BuildConstants::COMPILE_TIMESTAMP->value,
|
||||||
BuildConstants::NCC_BUILD_VERSION,
|
BuildConstants::NCC_BUILD_VERSION->value,
|
||||||
BuildConstants::NCC_BUILD_FLAGS,
|
BuildConstants::NCC_BUILD_FLAGS->value,
|
||||||
BuildConstants::NCC_BUILD_BRANCH
|
BuildConstants::NCC_BUILD_BRANCH->value
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
time(),
|
time(),
|
||||||
|
@ -150,10 +213,10 @@
|
||||||
|
|
||||||
return str_replace(
|
return str_replace(
|
||||||
[
|
[
|
||||||
InstallConstants::INSTALL_PATH,
|
InstallConstants::INSTALL_PATH->value,
|
||||||
InstallConstants::INSTALL_PATH_BIN,
|
InstallConstants::INSTALL_PATH_BIN->value,
|
||||||
InstallConstants::INSTALL_PATH_SRC,
|
InstallConstants::INSTALL_PATH_SRC->value,
|
||||||
InstallConstants::INSTALL_PATH_DATA
|
InstallConstants::INSTALL_PATH_DATA->value
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
$installation_paths->getInstallationpath(),
|
$installation_paths->getInstallationpath(),
|
||||||
|
@ -178,36 +241,36 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
return str_replace([
|
return str_replace([
|
||||||
DateTimeConstants::d,
|
DateTimeConstants::d->value,
|
||||||
DateTimeConstants::D,
|
DateTimeConstants::D->value,
|
||||||
DateTimeConstants::j,
|
DateTimeConstants::j->value,
|
||||||
DateTimeConstants::l,
|
DateTimeConstants::l->value,
|
||||||
DateTimeConstants::N,
|
DateTimeConstants::N->value,
|
||||||
DateTimeConstants::S,
|
DateTimeConstants::S->value,
|
||||||
DateTimeConstants::w,
|
DateTimeConstants::w->value,
|
||||||
DateTimeConstants::z,
|
DateTimeConstants::z->value,
|
||||||
DateTimeConstants::W,
|
DateTimeConstants::W->value,
|
||||||
DateTimeConstants::F,
|
DateTimeConstants::F->value,
|
||||||
DateTimeConstants::m,
|
DateTimeConstants::m->value,
|
||||||
DateTimeConstants::M,
|
DateTimeConstants::M->value,
|
||||||
DateTimeConstants::n,
|
DateTimeConstants::n->value,
|
||||||
DateTimeConstants::t,
|
DateTimeConstants::t->value,
|
||||||
DateTimeConstants::L,
|
DateTimeConstants::L->value,
|
||||||
DateTimeConstants::o,
|
DateTimeConstants::o->value,
|
||||||
DateTimeConstants::Y,
|
DateTimeConstants::Y->value,
|
||||||
DateTimeConstants::y,
|
DateTimeConstants::y->value,
|
||||||
DateTimeConstants::a,
|
DateTimeConstants::a->value,
|
||||||
DateTimeConstants::A,
|
DateTimeConstants::A->value,
|
||||||
DateTimeConstants::B,
|
DateTimeConstants::B->value,
|
||||||
DateTimeConstants::g,
|
DateTimeConstants::g->value,
|
||||||
DateTimeConstants::G,
|
DateTimeConstants::G->value,
|
||||||
DateTimeConstants::h,
|
DateTimeConstants::h->value,
|
||||||
DateTimeConstants::H,
|
DateTimeConstants::H->value,
|
||||||
DateTimeConstants::i,
|
DateTimeConstants::i->value,
|
||||||
DateTimeConstants::s,
|
DateTimeConstants::s->value,
|
||||||
DateTimeConstants::c,
|
DateTimeConstants::c->value,
|
||||||
DateTimeConstants::r,
|
DateTimeConstants::r->value,
|
||||||
DateTimeConstants::u
|
DateTimeConstants::u->value
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
date('d', $timestamp),
|
date('d', $timestamp),
|
||||||
|
@ -257,7 +320,7 @@
|
||||||
|
|
||||||
if(function_exists('getcwd'))
|
if(function_exists('getcwd'))
|
||||||
{
|
{
|
||||||
$input = str_replace(RuntimeConstants::CWD, getcwd(), $input);
|
$input = str_replace(RuntimeConstants::CWD->value, getcwd(), $input);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -266,7 +329,7 @@
|
||||||
|
|
||||||
if(function_exists('getmypid'))
|
if(function_exists('getmypid'))
|
||||||
{
|
{
|
||||||
$input = str_replace(RuntimeConstants::PID, getmypid(), $input);
|
$input = str_replace(RuntimeConstants::PID->value, getmypid(), $input);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -275,7 +338,7 @@
|
||||||
|
|
||||||
if(function_exists('getmyuid'))
|
if(function_exists('getmyuid'))
|
||||||
{
|
{
|
||||||
$input = str_replace(RuntimeConstants::UID, getmyuid(), $input);
|
$input = str_replace(RuntimeConstants::UID->value, getmyuid(), $input);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -284,7 +347,7 @@
|
||||||
|
|
||||||
if(function_exists('getmygid'))
|
if(function_exists('getmygid'))
|
||||||
{
|
{
|
||||||
$input = str_replace(RuntimeConstants::GID, getmygid(), $input);
|
$input = str_replace(RuntimeConstants::GID->value, getmygid(), $input);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -293,7 +356,7 @@
|
||||||
|
|
||||||
if(function_exists('get_current_user'))
|
if(function_exists('get_current_user'))
|
||||||
{
|
{
|
||||||
$input = str_replace(RuntimeConstants::USER, get_current_user(), $input);
|
$input = str_replace(RuntimeConstants::USER->value, get_current_user(), $input);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
57
src/ncc/Classes/NccExtension/NccCompiler.php
Normal file → Executable file
|
@ -59,11 +59,17 @@
|
||||||
*/
|
*/
|
||||||
private $project_manager;
|
private $project_manager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $merged_dependencies;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ProjectManager $project_manager
|
* @param ProjectManager $project_manager
|
||||||
*/
|
*/
|
||||||
public function __construct(ProjectManager $project_manager)
|
public function __construct(ProjectManager $project_manager)
|
||||||
{
|
{
|
||||||
|
$this->merged_dependencies = [];
|
||||||
$this->project_manager = $project_manager;
|
$this->project_manager = $project_manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,16 +93,17 @@
|
||||||
* @throws PathNotFoundException
|
* @throws PathNotFoundException
|
||||||
* @noinspection UnusedFunctionResultInspection
|
* @noinspection UnusedFunctionResultInspection
|
||||||
*/
|
*/
|
||||||
public function build(string $build_configuration=BuildConfigurationValues::DEFAULT, array $options=[]): string
|
public function build(string $build_configuration=BuildConfigurationValues::DEFAULT->value, array $options=[]): string
|
||||||
{
|
{
|
||||||
|
$this->merged_dependencies = [];
|
||||||
$configuration = $this->project_manager->getProjectConfiguration()->getBuild()->getBuildConfiguration($build_configuration);
|
$configuration = $this->project_manager->getProjectConfiguration()->getBuild()->getBuildConfiguration($build_configuration);
|
||||||
$configuration->setOptions(array_merge($configuration->getOptions(), $options));
|
$configuration->setOptions(array_merge($configuration->getOptions(), $options));
|
||||||
$static_dependencies = isset($configuration->getOptions()[BuildConfigurationOptions::STATIC_DEPENDENCIES]);
|
$static_dependencies = isset($configuration->getOptions()[BuildConfigurationOptions::STATIC_DEPENDENCIES->value]);
|
||||||
|
|
||||||
if(isset($configuration->getOptions()[BuildConfigurationOptions::OUTPUT_FILE]))
|
if(isset($configuration->getOptions()[BuildConfigurationOptions::OUTPUT_FILE->value]))
|
||||||
{
|
{
|
||||||
$package_path = ConstantCompiler::compileConstants(
|
$package_path = ConstantCompiler::compileConstants(
|
||||||
$this->project_manager->getProjectConfiguration(), $configuration->getOptions()[BuildConfigurationOptions::OUTPUT_FILE]
|
$this->project_manager->getProjectConfiguration(), $configuration->getOptions()[BuildConfigurationOptions::OUTPUT_FILE->value]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -122,7 +129,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debugging information
|
// Debugging information
|
||||||
if(Resolver::checkLogLevel(LogLevel::DEBUG, Main::getLogLevel()))
|
if(LogLevel::DEBUG->checkLogLevel(Main::getLogLevel()))
|
||||||
{
|
{
|
||||||
foreach($this->project_manager->getProjectConfiguration()->getAssembly()->toArray() as $prop => $value)
|
foreach($this->project_manager->getProjectConfiguration()->getAssembly()->toArray() as $prop => $value)
|
||||||
{
|
{
|
||||||
|
@ -164,7 +171,7 @@
|
||||||
|
|
||||||
foreach($execution_units as $unit)
|
foreach($execution_units as $unit)
|
||||||
{
|
{
|
||||||
$progress_bar->setMiscText($unit->getExecutionPolicy()->getName());
|
$progress_bar->setMiscText(basename($unit->getExecutionPolicy()->getName()));
|
||||||
//$progress++;
|
//$progress++;
|
||||||
//Console::inlineProgressBar($progress, $steps);
|
//Console::inlineProgressBar($progress, $steps);
|
||||||
$package_writer->addExecutionUnit($unit);
|
$package_writer->addExecutionUnit($unit);
|
||||||
|
@ -177,7 +184,7 @@
|
||||||
{
|
{
|
||||||
//$progress++;
|
//$progress++;
|
||||||
//Console::inlineProgressBar($progress, $steps);
|
//Console::inlineProgressBar($progress, $steps);
|
||||||
$progress_bar->setMiscText($component);
|
$progress_bar->setMiscText(basename($component));
|
||||||
Console::outVerbose(sprintf('Compiling \'%s\'', $component));
|
Console::outVerbose(sprintf('Compiling \'%s\'', $component));
|
||||||
|
|
||||||
$this->processComponent($package_writer, $component);
|
$this->processComponent($package_writer, $component);
|
||||||
|
@ -189,7 +196,7 @@
|
||||||
{
|
{
|
||||||
//$progress++;
|
//$progress++;
|
||||||
//Console::inlineProgressBar($progress, $steps);
|
//Console::inlineProgressBar($progress, $steps);
|
||||||
$progress_bar->setMiscText($resource);
|
$progress_bar->setMiscText(basename($resource));
|
||||||
Console::outVerbose(sprintf('Processing \'%s\'', $resource));
|
Console::outVerbose(sprintf('Processing \'%s\'', $resource));
|
||||||
|
|
||||||
$this->processResource($package_writer, $resource);
|
$this->processResource($package_writer, $resource);
|
||||||
|
@ -234,13 +241,14 @@
|
||||||
/** @noinspection UnusedFunctionResultInspection */
|
/** @noinspection UnusedFunctionResultInspection */
|
||||||
$package_writer->addDependencyConfiguration($dependency);
|
$package_writer->addDependencyConfiguration($dependency);
|
||||||
|
|
||||||
if(!$static)
|
if(!$static || in_array($dependency->getName(), $this->merged_dependencies, true))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$entry = (new PackageManager())->getPackageLock()->getVersionEntry($dependency->getName(), $dependency->getVersion());
|
$entry = (new PackageManager())->getPackageLock()->getVersionEntry($dependency->getName(), $dependency->getVersion());
|
||||||
$package_writer->merge((new PackageReader($entry->getShadowPackagePath($dependency->getName()))));
|
$package_writer->merge((new PackageReader($entry->getShadowPackagePath($dependency->getName()))));
|
||||||
|
$this->merged_dependencies[] = $dependency->getName();
|
||||||
|
|
||||||
foreach($entry->getDependencies() as $sub_dependency)
|
foreach($entry->getDependencies() as $sub_dependency)
|
||||||
{
|
{
|
||||||
|
@ -261,25 +269,25 @@
|
||||||
{
|
{
|
||||||
$package_writer = new PackageWriter($path);
|
$package_writer = new PackageWriter($path);
|
||||||
|
|
||||||
if(isset($build_configuration->getOptions()[BuildConfigurationOptions::COMPRESSION]))
|
if(isset($build_configuration->getOptions()[BuildConfigurationOptions::COMPRESSION->value]))
|
||||||
{
|
{
|
||||||
$package_writer->addFlag(PackageFlags::COMPRESSION);
|
$package_writer->addFlag(PackageFlags::COMPRESSION);
|
||||||
switch(strtolower($build_configuration->getOptions()[BuildConfigurationOptions::COMPRESSION]))
|
switch(strtolower($build_configuration->getOptions()[BuildConfigurationOptions::COMPRESSION->value]))
|
||||||
{
|
{
|
||||||
case BuildConfigurationOptions\CompressionOptions::HIGH:
|
case BuildConfigurationOptions\CompressionOptions::HIGH->value:
|
||||||
$package_writer->addFlag(PackageFlags::HIGH_COMPRESSION);
|
$package_writer->addFlag(PackageFlags::HIGH_COMPRESSION);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BuildConfigurationOptions\CompressionOptions::MEDIUM:
|
case BuildConfigurationOptions\CompressionOptions::MEDIUM->value:
|
||||||
$package_writer->addFlag(PackageFlags::MEDIUM_COMPRESSION);
|
$package_writer->addFlag(PackageFlags::MEDIUM_COMPRESSION);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BuildConfigurationOptions\CompressionOptions::LOW:
|
case BuildConfigurationOptions\CompressionOptions::LOW->value:
|
||||||
$package_writer->addFlag(PackageFlags::LOW_COMPRESSION);
|
$package_writer->addFlag(PackageFlags::LOW_COMPRESSION);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new NotSupportedException(sprintf('The compression level \'%s\' is not supported', $build_configuration->getOptions()[BuildConfigurationOptions::COMPRESSION]));
|
throw new NotSupportedException(sprintf('The compression level \'%s\' is not supported', $build_configuration->getOptions()[BuildConfigurationOptions::COMPRESSION->value]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,29 +335,38 @@
|
||||||
* @param string $build_configuration
|
* @param string $build_configuration
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function processMetadata(PackageWriter $package_writer, string $build_configuration=BuildConfigurationValues::DEFAULT): void
|
public function processMetadata(PackageWriter $package_writer, string $build_configuration=BuildConfigurationValues::DEFAULT->value): void
|
||||||
{
|
{
|
||||||
$metadata = new Metadata($this->project_manager->getProjectConfiguration()->getProject()->getCompiler());
|
$metadata = new Metadata($this->project_manager->getProjectConfiguration()->getProject()->getCompiler());
|
||||||
|
|
||||||
$metadata->addOptions($this->project_manager->getProjectConfiguration()->getBuild()->getOptions($build_configuration));
|
$metadata->addOptions($this->project_manager->getProjectConfiguration()->getBuild()->getOptions($build_configuration));
|
||||||
$metadata->addOptions($this->project_manager->getProjectConfiguration()->getProject()->getOptions());
|
$metadata->addOptions($this->project_manager->getProjectConfiguration()->getProject()->getOptions());
|
||||||
|
$metadata->addConstants($this->project_manager->getConstants($build_configuration));
|
||||||
$metadata->setUpdateSource($this->project_manager->getProjectConfiguration()->getProject()->getUpdateSource());
|
$metadata->setUpdateSource($this->project_manager->getProjectConfiguration()->getProject()->getUpdateSource());
|
||||||
$metadata->setMainExecutionPolicy($this->project_manager->getProjectConfiguration()->getBuild()->getMain());
|
$metadata->setMainExecutionPolicy($this->project_manager->getProjectConfiguration()->getBuild()->getMain());
|
||||||
$metadata->setInstaller($this->project_manager->getProjectConfiguration()->getInstaller());
|
$metadata->setInstaller($this->project_manager->getProjectConfiguration()->getInstaller());
|
||||||
|
|
||||||
// Strip out 'output_file' build artifact.
|
// Strip out 'output_file' build artifact.
|
||||||
if(isset($metadata->getOptions()[BuildConfigurationOptions::OUTPUT_FILE]))
|
if(isset($metadata->getOptions()[BuildConfigurationOptions::OUTPUT_FILE->value]))
|
||||||
{
|
{
|
||||||
$metadata->removeOption(BuildConfigurationOptions::OUTPUT_FILE);
|
$metadata->removeOption(BuildConfigurationOptions::OUTPUT_FILE->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Strip out 'static' build artifact, PackageFlags::STATIC_DEPENDENCIES is used instead
|
// Strip out 'static' build artifact, PackageFlags::STATIC_DEPENDENCIES is used instead
|
||||||
// Making this option redundant.
|
// Making this option redundant.
|
||||||
if(isset($metadata->getOptions()[BuildConfigurationOptions::STATIC_DEPENDENCIES]))
|
if(isset($metadata->getOptions()[BuildConfigurationOptions::STATIC_DEPENDENCIES->value]))
|
||||||
{
|
{
|
||||||
$metadata->removeOption(BuildConfigurationOptions::STATIC_DEPENDENCIES);
|
$metadata->removeOption(BuildConfigurationOptions::STATIC_DEPENDENCIES->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$compiled_constants = [];
|
||||||
|
foreach($this->project_manager->getConstants() as $constant => $value)
|
||||||
|
{
|
||||||
|
$compiled_constants[$constant] = ConstantCompiler::compileConstants($this->project_manager->getProjectConfiguration(), $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
$metadata->addConstants($compiled_constants);
|
||||||
|
|
||||||
/** @noinspection UnusedFunctionResultInspection */
|
/** @noinspection UnusedFunctionResultInspection */
|
||||||
$package_writer->setMetadata($metadata);
|
$package_writer->setMetadata($metadata);
|
||||||
}
|
}
|
||||||
|
|
329
src/ncc/Classes/PackageReader.php
Normal file → Executable file
|
@ -29,8 +29,8 @@
|
||||||
use ncc\Enums\Flags\PackageFlags;
|
use ncc\Enums\Flags\PackageFlags;
|
||||||
use ncc\Enums\PackageDirectory;
|
use ncc\Enums\PackageDirectory;
|
||||||
use ncc\Exceptions\ConfigurationException;
|
use ncc\Exceptions\ConfigurationException;
|
||||||
|
use ncc\Exceptions\IntegrityException;
|
||||||
use ncc\Exceptions\IOException;
|
use ncc\Exceptions\IOException;
|
||||||
use ncc\Exceptions\NotSupportedException;
|
|
||||||
use ncc\Objects\Package\Component;
|
use ncc\Objects\Package\Component;
|
||||||
use ncc\Objects\Package\ExecutionUnit;
|
use ncc\Objects\Package\ExecutionUnit;
|
||||||
use ncc\Objects\Package\Metadata;
|
use ncc\Objects\Package\Metadata;
|
||||||
|
@ -47,32 +47,32 @@
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $package_offset;
|
private $packageOffset;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $package_length;
|
private $packageLength;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $header_offset;
|
private $headerOffset;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $header_length;
|
private $headerLength;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $data_offset;
|
private $dataOffset;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $data_length;
|
private $dataLength;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
|
@ -82,7 +82,12 @@
|
||||||
/**
|
/**
|
||||||
* @var resource
|
* @var resource
|
||||||
*/
|
*/
|
||||||
private $package_file;
|
private $packageFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $packagePath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
|
@ -102,8 +107,10 @@
|
||||||
throw new IOException(sprintf('File \'%s\' does not exist', $file_path));
|
throw new IOException(sprintf('File \'%s\' does not exist', $file_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->package_file = fopen($file_path, 'rb');
|
$this->packagePath = $file_path;
|
||||||
if($this->package_file === false)
|
$this->packageFile = fopen($file_path, 'rb');
|
||||||
|
|
||||||
|
if($this->packageFile === false)
|
||||||
{
|
{
|
||||||
throw new IOException(sprintf('Failed to open file \'%s\'', $file_path));
|
throw new IOException(sprintf('Failed to open file \'%s\'', $file_path));
|
||||||
}
|
}
|
||||||
|
@ -115,41 +122,41 @@
|
||||||
// End of data: \xFF\xAA\x55\xF0
|
// End of data: \xFF\xAA\x55\xF0
|
||||||
|
|
||||||
// First find the offset of the package by searching for the magic bytes "ncc_pkg"
|
// First find the offset of the package by searching for the magic bytes "ncc_pkg"
|
||||||
$this->package_offset = 0;
|
$this->packageOffset = 0;
|
||||||
while(!feof($this->package_file))
|
while(!feof($this->packageFile))
|
||||||
{
|
{
|
||||||
$buffer = fread($this->package_file, 1024);
|
$buffer = fread($this->packageFile, 1024);
|
||||||
$buffer_length = strlen($buffer);
|
$buffer_length = strlen($buffer);
|
||||||
$this->package_offset += $buffer_length;
|
$this->packageOffset += $buffer_length;
|
||||||
|
|
||||||
if (($position = strpos($buffer, "ncc_pkg")) !== false)
|
if (($position = strpos($buffer, "ncc_pkg")) !== false)
|
||||||
{
|
{
|
||||||
$this->package_offset -= $buffer_length - $position;
|
$this->packageOffset -= $buffer_length - $position;
|
||||||
$this->package_length = 7; // ncc_pkg
|
$this->packageLength = 7; // ncc_pkg
|
||||||
$this->header_offset = $this->package_offset + 7;
|
$this->headerOffset = $this->packageOffset + 7;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for sanity reasons
|
// Check for sanity reasons
|
||||||
if($this->package_offset === null || $this->package_length === null)
|
if($this->packageOffset === null || $this->packageLength === null)
|
||||||
{
|
{
|
||||||
throw new IOException(sprintf('File \'%s\' is not a valid package file (missing magic bytes)', $file_path));
|
throw new IOException(sprintf('File \'%s\' is not a valid package file (missing magic bytes)', $file_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Seek the header until the end of headers byte sequence (1F 1F 1F 1F)
|
// Seek the header until the end of headers byte sequence (1F 1F 1F 1F)
|
||||||
fseek($this->package_file, $this->header_offset);
|
fseek($this->packageFile, $this->headerOffset);
|
||||||
while (!feof($this->package_file))
|
while (!feof($this->packageFile))
|
||||||
{
|
{
|
||||||
$this->headers .= fread($this->package_file, 1024);
|
$this->headers .= fread($this->packageFile, 1024);
|
||||||
|
|
||||||
// Search for the position of "1F 1F 1F 1F" within the buffer
|
// Search for the position of "1F 1F 1F 1F" within the buffer
|
||||||
if (($position = strpos($this->headers, "\x1F\x1F\x1F\x1F")) !== false)
|
if (($position = strpos($this->headers, "\x1F\x1F\x1F\x1F")) !== false)
|
||||||
{
|
{
|
||||||
$this->headers = substr($this->headers, 0, $position);
|
$this->headers = substr($this->headers, 0, $position);
|
||||||
$this->header_length = strlen($this->headers);
|
$this->headerLength = strlen($this->headers);
|
||||||
$this->package_length += $this->header_length + 4;
|
$this->packageLength += $this->headerLength + 4;
|
||||||
$this->data_offset = $this->header_offset + $this->header_length + 4;
|
$this->dataOffset = $this->headerOffset + $this->headerLength + 4;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,27 +175,38 @@
|
||||||
throw new IOException(sprintf('File \'%s\' is not a valid package file (corrupted header)', $file_path), $e);
|
throw new IOException(sprintf('File \'%s\' is not a valid package file (corrupted header)', $file_path), $e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($this->headers[PackageStructure::FILE_VERSION]))
|
if(!isset($this->headers[PackageStructure::FILE_VERSION->value]))
|
||||||
{
|
{
|
||||||
throw new IOException(sprintf('File \'%s\' is not a valid package file (invalid header)', $file_path));
|
throw new IOException(sprintf('File \'%s\' is not a valid package file (invalid header)', $file_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Seek the data until the end of the package (FF AA 55 F0)
|
// Seek the data until the end of the package (FF AA 55 F0)
|
||||||
fseek($this->package_file, $this->data_offset);
|
fseek($this->packageFile, $this->dataOffset);
|
||||||
while(!feof($this->package_file))
|
$buffer = '';
|
||||||
|
while(!feof($this->packageFile))
|
||||||
{
|
{
|
||||||
$buffer = fread($this->package_file, 1024);
|
$current_chunk = fread($this->packageFile, 1024);
|
||||||
$this->data_length += strlen($buffer);
|
$this->dataLength += strlen($current_chunk);
|
||||||
|
$buffer .= $current_chunk;
|
||||||
|
|
||||||
|
// If we detect the end-of-data byte sequence
|
||||||
if (($position = strpos($buffer, "\xFF\xAA\x55\xF0")) !== false)
|
if (($position = strpos($buffer, "\xFF\xAA\x55\xF0")) !== false)
|
||||||
{
|
{
|
||||||
$this->data_length -= strlen($buffer) - $position;
|
$this->dataLength -= strlen($buffer) - $position;
|
||||||
$this->package_length += $this->data_length + 4;
|
$this->packageLength += $this->dataLength + 4;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if the buffer is 1MB or larger
|
||||||
|
if(strlen($buffer) > 1048576)
|
||||||
|
{
|
||||||
|
// Remove the first 512kb of the buffer
|
||||||
|
$buffer = substr($buffer, 512000);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->data_length === null)
|
}
|
||||||
|
|
||||||
|
if($this->dataLength === null || $this->dataLength === 0)
|
||||||
{
|
{
|
||||||
throw new IOException(sprintf('File \'%s\' is not a valid package file (missing end of package)', $file_path));
|
throw new IOException(sprintf('File \'%s\' is not a valid package file (missing end of package)', $file_path));
|
||||||
}
|
}
|
||||||
|
@ -213,7 +231,7 @@
|
||||||
*/
|
*/
|
||||||
public function getFileVersion(): string
|
public function getFileVersion(): string
|
||||||
{
|
{
|
||||||
return $this->headers[PackageStructure::FILE_VERSION];
|
return $this->headers[PackageStructure::FILE_VERSION->value];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -223,7 +241,7 @@
|
||||||
*/
|
*/
|
||||||
public function getFlags(): array
|
public function getFlags(): array
|
||||||
{
|
{
|
||||||
return $this->headers[PackageStructure::FLAGS];
|
return $this->headers[PackageStructure::FLAGS->value];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -234,7 +252,7 @@
|
||||||
*/
|
*/
|
||||||
public function getFlag(string $name): bool
|
public function getFlag(string $name): bool
|
||||||
{
|
{
|
||||||
return in_array($name, $this->headers[PackageStructure::FLAGS], true);
|
return in_array($name, $this->headers[PackageStructure::FLAGS->value], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -244,7 +262,7 @@
|
||||||
*/
|
*/
|
||||||
public function getDirectory(): array
|
public function getDirectory(): array
|
||||||
{
|
{
|
||||||
return $this->headers[PackageStructure::DIRECTORY];
|
return $this->headers[PackageStructure::DIRECTORY->value];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -255,20 +273,20 @@
|
||||||
*/
|
*/
|
||||||
public function get(string $name): string
|
public function get(string $name): string
|
||||||
{
|
{
|
||||||
if(!isset($this->headers[PackageStructure::DIRECTORY][$name]))
|
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$name]))
|
||||||
{
|
{
|
||||||
throw new RuntimeException(sprintf('File \'%s\' not found in package', $name));
|
throw new RuntimeException(sprintf('File \'%s\' not found in package \'%s\'', $name, $this->packagePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
$location = explode(':', $this->headers[PackageStructure::DIRECTORY][$name]);
|
$location = explode(':', $this->headers[PackageStructure::DIRECTORY->value][$name]);
|
||||||
fseek($this->package_file, ($this->data_offset + (int)$location[0]));
|
fseek($this->packageFile, ($this->dataOffset + (int)$location[0]));
|
||||||
|
|
||||||
if(in_array(PackageFlags::COMPRESSION, $this->headers[PackageStructure::FLAGS], true))
|
if(in_array(PackageFlags::COMPRESSION->value, $this->headers[PackageStructure::FLAGS->value], true))
|
||||||
{
|
{
|
||||||
return gzuncompress(fread($this->package_file, (int)$location[1]));
|
return gzuncompress(fread($this->packageFile, (int)$location[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
return fread($this->package_file, (int)$location[1]);
|
return fread($this->packageFile, (int)$location[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -279,12 +297,12 @@
|
||||||
*/
|
*/
|
||||||
public function getPointer(string $name): array
|
public function getPointer(string $name): array
|
||||||
{
|
{
|
||||||
if(!isset($this->headers[PackageStructure::DIRECTORY][$name]))
|
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$name]))
|
||||||
{
|
{
|
||||||
throw new RuntimeException(sprintf('Resource \'%s\' not found in package', $name));
|
throw new RuntimeException(sprintf('Resource \'%s\' not found in package \'%s\'', $name, $this->packagePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
$location = explode(':', $this->headers[PackageStructure::DIRECTORY][$name]);
|
$location = explode(':', $this->headers[PackageStructure::DIRECTORY->value][$name]);
|
||||||
return [(int)$location[0], (int)$location[1]];
|
return [(int)$location[0], (int)$location[1]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,7 +314,7 @@
|
||||||
*/
|
*/
|
||||||
public function exists(string $name): bool
|
public function exists(string $name): bool
|
||||||
{
|
{
|
||||||
return isset($this->headers[PackageStructure::DIRECTORY][$name]);
|
return isset($this->headers[PackageStructure::DIRECTORY->value][$name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -308,8 +326,8 @@
|
||||||
*/
|
*/
|
||||||
public function getByPointer(int $pointer, int $length): string
|
public function getByPointer(int $pointer, int $length): string
|
||||||
{
|
{
|
||||||
fseek($this->package_file, ($this->header_length + $pointer));
|
fseek($this->packageFile, ($this->headerLength + $pointer));
|
||||||
return fread($this->package_file, $length);
|
return fread($this->packageFile, $length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -317,22 +335,31 @@
|
||||||
*
|
*
|
||||||
* @return Assembly
|
* @return Assembly
|
||||||
* @throws ConfigurationException
|
* @throws ConfigurationException
|
||||||
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public function getAssembly(): Assembly
|
public function getAssembly(): Assembly
|
||||||
{
|
{
|
||||||
$directory = sprintf('@%s', PackageDirectory::ASSEMBLY);
|
$directory = sprintf('@%s', PackageDirectory::ASSEMBLY->value);
|
||||||
|
|
||||||
if(isset($this->cache[$directory]))
|
if(isset($this->cache[$directory]))
|
||||||
{
|
{
|
||||||
return $this->cache[$directory];
|
return $this->cache[$directory];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($this->headers[PackageStructure::DIRECTORY][$directory]))
|
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$directory]))
|
||||||
{
|
{
|
||||||
throw new ConfigurationException('Package does not contain an assembly');
|
throw new ConfigurationException(sprintf('Assembly object not found in package \'%s\'', $this->packagePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
$assembly = Assembly::fromArray(ZiProto::decode($this->get($directory)));
|
$assembly = Assembly::fromArray(ZiProto::decode($this->get($directory)));
|
||||||
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new IntegrityException(sprintf('Failed to decode assembly from package \'%s\' using ZiProto: %s', $this->packagePath, $e->getMessage()), $e);
|
||||||
|
}
|
||||||
|
|
||||||
$this->cache[$directory] = $assembly;
|
$this->cache[$directory] = $assembly;
|
||||||
return $assembly;
|
return $assembly;
|
||||||
}
|
}
|
||||||
|
@ -342,23 +369,31 @@
|
||||||
*
|
*
|
||||||
* @return Metadata
|
* @return Metadata
|
||||||
* @throws ConfigurationException
|
* @throws ConfigurationException
|
||||||
* @throws NotSupportedException
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public function getMetadata(): Metadata
|
public function getMetadata(): Metadata
|
||||||
{
|
{
|
||||||
$directory = sprintf('@%s', PackageDirectory::METADATA);
|
$directory = sprintf('@%s', PackageDirectory::METADATA->value);
|
||||||
|
|
||||||
if(isset($this->cache[$directory]))
|
if(isset($this->cache[$directory]))
|
||||||
{
|
{
|
||||||
return $this->cache[$directory];
|
return $this->cache[$directory];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($this->headers[PackageStructure::DIRECTORY][$directory]))
|
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$directory]))
|
||||||
{
|
{
|
||||||
throw new ConfigurationException('Package does not contain metadata');
|
throw new ConfigurationException(sprintf('Metadata object not found in package \'%s\'', $this->packagePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
$metadata = Metadata::fromArray(ZiProto::decode($this->get($directory)));
|
$metadata = Metadata::fromArray(ZiProto::decode($this->get($directory)));
|
||||||
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new IntegrityException(sprintf('Failed to decode metadata from package \'%s\' using ZiProto: %s', $this->packagePath, $e->getMessage()), $e);
|
||||||
|
}
|
||||||
|
|
||||||
foreach($this->getFlags() as $flag)
|
foreach($this->getFlags() as $flag)
|
||||||
{
|
{
|
||||||
$metadata->setOption($flag, true);
|
$metadata->setOption($flag, true);
|
||||||
|
@ -372,22 +407,31 @@
|
||||||
* Optional. Returns the package's installer
|
* Optional. Returns the package's installer
|
||||||
*
|
*
|
||||||
* @return Installer|null
|
* @return Installer|null
|
||||||
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public function getInstaller(): ?Installer
|
public function getInstaller(): ?Installer
|
||||||
{
|
{
|
||||||
$directory = sprintf('@%s', PackageDirectory::INSTALLER);
|
$directory = sprintf('@%s', PackageDirectory::INSTALLER->value);
|
||||||
|
|
||||||
if(isset($this->cache[$directory]))
|
if(isset($this->cache[$directory]))
|
||||||
{
|
{
|
||||||
return $this->cache[$directory];
|
return $this->cache[$directory];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($this->headers[PackageStructure::DIRECTORY][$directory]))
|
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$directory]))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
$installer = Installer::fromArray(ZiProto::decode($this->get($directory)));
|
$installer = Installer::fromArray(ZiProto::decode($this->get($directory)));
|
||||||
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new IntegrityException(sprintf('Failed to decode installer from package \'%s\' using ZiProto: %s', $this->packagePath, $e->getMessage()), $e);
|
||||||
|
}
|
||||||
|
|
||||||
$this->cache[$directory] = $installer;
|
$this->cache[$directory] = $installer;
|
||||||
return $installer;
|
return $installer;
|
||||||
}
|
}
|
||||||
|
@ -400,9 +444,9 @@
|
||||||
public function getDependencies(): array
|
public function getDependencies(): array
|
||||||
{
|
{
|
||||||
$dependencies = [];
|
$dependencies = [];
|
||||||
$directory = sprintf('@%s:', PackageDirectory::DEPENDENCIES);
|
$directory = sprintf('@%s:', PackageDirectory::DEPENDENCIES->value);
|
||||||
|
|
||||||
foreach($this->headers[PackageStructure::DIRECTORY] as $name => $location)
|
foreach($this->headers[PackageStructure::DIRECTORY->value] as $name => $location)
|
||||||
{
|
{
|
||||||
if(str_starts_with($name, $directory))
|
if(str_starts_with($name, $directory))
|
||||||
{
|
{
|
||||||
|
@ -419,17 +463,25 @@
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return Dependency
|
* @return Dependency
|
||||||
* @throws ConfigurationException
|
* @throws ConfigurationException
|
||||||
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public function getDependency(string $name): Dependency
|
public function getDependency(string $name): Dependency
|
||||||
{
|
{
|
||||||
$dependency_name = sprintf('@%s:%s', PackageDirectory::DEPENDENCIES, $name);
|
$dependency_name = sprintf('@%s:%s', PackageDirectory::DEPENDENCIES->value, $name);
|
||||||
if(!isset($this->headers[PackageStructure::DIRECTORY][$dependency_name]))
|
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$dependency_name]))
|
||||||
{
|
{
|
||||||
throw new ConfigurationException(sprintf('Dependency \'%s\' not found in package', $name));
|
throw new ConfigurationException(sprintf('Dependency \'%s\' not found in package \'%s\'', $name, $this->packagePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
return Dependency::fromArray(ZiProto::decode($this->get($dependency_name)));
|
return Dependency::fromArray(ZiProto::decode($this->get($dependency_name)));
|
||||||
}
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new IntegrityException(sprintf('Failed to decode dependency \'%s\' from package \'%s\' using ZiProto: %s', $name, $this->packagePath, $e->getMessage()), $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a dependency from the package by pointer
|
* Returns a dependency from the package by pointer
|
||||||
|
@ -437,12 +489,19 @@
|
||||||
* @param int $pointer
|
* @param int $pointer
|
||||||
* @param int $length
|
* @param int $length
|
||||||
* @return Dependency
|
* @return Dependency
|
||||||
* @throws ConfigurationException
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public function getDependencyByPointer(int $pointer, int $length): Dependency
|
public function getDependencyByPointer(int $pointer, int $length): Dependency
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
return Dependency::fromArray(ZiProto::decode($this->getByPointer($pointer, $length)));
|
return Dependency::fromArray(ZiProto::decode($this->getByPointer($pointer, $length)));
|
||||||
}
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new IntegrityException(sprintf('Failed to decode dependency from pointer \'%s\' with length \'%s\' from package \'%s\' using ZiProto: %s', $pointer, $length, $this->packagePath, $e->getMessage()), $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of execution units from the package
|
* Returns an array of execution units from the package
|
||||||
|
@ -452,9 +511,9 @@
|
||||||
public function getExecutionUnits(): array
|
public function getExecutionUnits(): array
|
||||||
{
|
{
|
||||||
$execution_units = [];
|
$execution_units = [];
|
||||||
$directory = sprintf('@%s:', PackageDirectory::EXECUTION_UNITS);
|
$directory = sprintf('@%s:', PackageDirectory::EXECUTION_UNITS->value);
|
||||||
|
|
||||||
foreach($this->headers[PackageStructure::DIRECTORY] as $name => $location)
|
foreach($this->headers[PackageStructure::DIRECTORY->value] as $name => $location)
|
||||||
{
|
{
|
||||||
if(str_starts_with($name, $directory))
|
if(str_starts_with($name, $directory))
|
||||||
{
|
{
|
||||||
|
@ -471,17 +530,36 @@
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return ExecutionUnit
|
* @return ExecutionUnit
|
||||||
* @throws ConfigurationException
|
* @throws ConfigurationException
|
||||||
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public function getExecutionUnit(string $name): ExecutionUnit
|
public function getExecutionUnit(string $name): ExecutionUnit
|
||||||
{
|
{
|
||||||
$execution_unit_name = sprintf('@%s:%s', PackageDirectory::EXECUTION_UNITS, $name);
|
$execution_unit_name = sprintf('@%s:%s', PackageDirectory::EXECUTION_UNITS->value, $name);
|
||||||
if(!isset($this->headers[PackageStructure::DIRECTORY][$execution_unit_name]))
|
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$execution_unit_name]))
|
||||||
{
|
{
|
||||||
throw new ConfigurationException(sprintf('Execution unit \'%s\' not found in package', $name));
|
throw new ConfigurationException(sprintf('Execution unit \'%s\' not found in package \'%s\'', $name, $this->packagePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
return ExecutionUnit::fromArray(ZiProto::decode($this->get($execution_unit_name)));
|
return ExecutionUnit::fromArray(ZiProto::decode($this->get($execution_unit_name)));
|
||||||
}
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new IntegrityException(sprintf('Failed to decode execution unit \'%s\' from package file \'%s\' using ZiProto: %s', $name, $this->packagePath, $e->getMessage()), $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if an execution unit with the specified name exists in the package.
|
||||||
|
*
|
||||||
|
* @param string $name The name of the execution unit to check.
|
||||||
|
* @return bool True if the execution unit exists, false otherwise.
|
||||||
|
*/
|
||||||
|
public function executionUnitExists(string $name): bool
|
||||||
|
{
|
||||||
|
return isset($this->headers[PackageStructure::DIRECTORY->value][sprintf('@%s:%s', PackageDirectory::EXECUTION_UNITS->value, $name)]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an execution unit from the package by pointer
|
* Returns an execution unit from the package by pointer
|
||||||
|
@ -489,12 +567,19 @@
|
||||||
* @param int $pointer
|
* @param int $pointer
|
||||||
* @param int $length
|
* @param int $length
|
||||||
* @return ExecutionUnit
|
* @return ExecutionUnit
|
||||||
* @throws ConfigurationException
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public function getExecutionUnitByPointer(int $pointer, int $length): ExecutionUnit
|
public function getExecutionUnitByPointer(int $pointer, int $length): ExecutionUnit
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
return ExecutionUnit::fromArray(ZiProto::decode($this->getByPointer($pointer, $length)));
|
return ExecutionUnit::fromArray(ZiProto::decode($this->getByPointer($pointer, $length)));
|
||||||
}
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new IntegrityException(sprintf('Failed to decode execution unit from pointer \'%s\' with length \'%s\' from package \'%s\' using ZiProto: %s', $pointer, $length, $this->packagePath, $e->getMessage()), $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the package's component pointers
|
* Returns the package's component pointers
|
||||||
|
@ -504,9 +589,9 @@
|
||||||
public function getComponents(): array
|
public function getComponents(): array
|
||||||
{
|
{
|
||||||
$components = [];
|
$components = [];
|
||||||
$directory = sprintf('@%s:', PackageDirectory::COMPONENTS);
|
$directory = sprintf('@%s:', PackageDirectory::COMPONENTS->value);
|
||||||
|
|
||||||
foreach($this->headers[PackageStructure::DIRECTORY] as $name => $location)
|
foreach($this->headers[PackageStructure::DIRECTORY->value] as $name => $location)
|
||||||
{
|
{
|
||||||
if(str_starts_with($name, $directory))
|
if(str_starts_with($name, $directory))
|
||||||
{
|
{
|
||||||
|
@ -525,9 +610,9 @@
|
||||||
public function getClassMap(): array
|
public function getClassMap(): array
|
||||||
{
|
{
|
||||||
$class_map = [];
|
$class_map = [];
|
||||||
$directory = sprintf('@%s:', PackageDirectory::CLASS_POINTER);
|
$directory = sprintf('@%s:', PackageDirectory::CLASS_POINTER->value);
|
||||||
|
|
||||||
foreach($this->headers[PackageStructure::DIRECTORY] as $name => $location)
|
foreach($this->headers[PackageStructure::DIRECTORY->value] as $name => $location)
|
||||||
{
|
{
|
||||||
if(str_starts_with($name, $directory))
|
if(str_starts_with($name, $directory))
|
||||||
{
|
{
|
||||||
|
@ -544,17 +629,25 @@
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return Component
|
* @return Component
|
||||||
* @throws ConfigurationException
|
* @throws ConfigurationException
|
||||||
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public function getComponent(string $name): Component
|
public function getComponent(string $name): Component
|
||||||
{
|
{
|
||||||
$component_name = sprintf('@%s:%s', PackageDirectory::COMPONENTS, $name);
|
$component_name = sprintf('@%s:%s', PackageDirectory::COMPONENTS->value, $name);
|
||||||
if(!isset($this->headers[PackageStructure::DIRECTORY][$component_name]))
|
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$component_name]))
|
||||||
{
|
{
|
||||||
throw new ConfigurationException(sprintf('Component \'%s\' not found in package', $name));
|
throw new ConfigurationException(sprintf('Component \'%s\' not found in package \'%s\'', $name, $this->packagePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
return Component::fromArray(ZiProto::decode($this->get($component_name)));
|
return Component::fromArray(ZiProto::decode($this->get($component_name)));
|
||||||
}
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new IntegrityException(sprintf('Failed to decode component \'%s\' from package \'%s\' using ZiProto: %s', $name, $this->packagePath, $e->getMessage()), $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a component from the package by pointer
|
* Returns a component from the package by pointer
|
||||||
|
@ -562,12 +655,19 @@
|
||||||
* @param int $pointer
|
* @param int $pointer
|
||||||
* @param int $length
|
* @param int $length
|
||||||
* @return Component
|
* @return Component
|
||||||
* @throws ConfigurationException
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public function getComponentByPointer(int $pointer, int $length): Component
|
public function getComponentByPointer(int $pointer, int $length): Component
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
return Component::fromArray(ZiProto::decode($this->getByPointer($pointer, $length)));
|
return Component::fromArray(ZiProto::decode($this->getByPointer($pointer, $length)));
|
||||||
}
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new IntegrityException(sprintf('Failed to decode component from pointer \'%s\' with length \'%s\' from package \'%s\' using ZiProto: %s', $pointer, $length, $this->packagePath, $e->getMessage()), $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a component from the package by a class pointer
|
* Returns a component from the package by a class pointer
|
||||||
|
@ -575,17 +675,25 @@
|
||||||
* @param string $class
|
* @param string $class
|
||||||
* @return Component
|
* @return Component
|
||||||
* @throws ConfigurationException
|
* @throws ConfigurationException
|
||||||
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public function getComponentByClass(string $class): Component
|
public function getComponentByClass(string $class): Component
|
||||||
{
|
{
|
||||||
$class_name = sprintf('@%s:%s', PackageDirectory::CLASS_POINTER, $class);
|
$class_name = sprintf('@%s:%s', PackageDirectory::CLASS_POINTER->value, $class);
|
||||||
if(!isset($this->headers[PackageStructure::DIRECTORY][$class_name]))
|
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$class_name]))
|
||||||
{
|
{
|
||||||
throw new ConfigurationException(sprintf('Class map \'%s\' not found in package', $class));
|
throw new ConfigurationException(sprintf('Class map \'%s\' not found in package \'%s\'', $class, $this->packagePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
return Component::fromArray(ZiProto::decode($this->get($class_name)));
|
return Component::fromArray(ZiProto::decode($this->get($class_name)));
|
||||||
}
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new IntegrityException(sprintf('Failed to decode component from class pointer \'%s\' from package \'%s\' using ZiProto: %s', $class, $this->packagePath, $e->getMessage()), $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of resource pointers from the package
|
* Returns an array of resource pointers from the package
|
||||||
|
@ -595,9 +703,9 @@
|
||||||
public function getResources(): array
|
public function getResources(): array
|
||||||
{
|
{
|
||||||
$resources = [];
|
$resources = [];
|
||||||
$directory = sprintf('@%s:', PackageDirectory::RESOURCES);
|
$directory = sprintf('@%s:', PackageDirectory::RESOURCES->value);
|
||||||
|
|
||||||
foreach($this->headers[PackageStructure::DIRECTORY] as $name => $location)
|
foreach($this->headers[PackageStructure::DIRECTORY->value] as $name => $location)
|
||||||
{
|
{
|
||||||
if(str_starts_with($name, $directory))
|
if(str_starts_with($name, $directory))
|
||||||
{
|
{
|
||||||
|
@ -614,17 +722,25 @@
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return Resource
|
* @return Resource
|
||||||
* @throws ConfigurationException
|
* @throws ConfigurationException
|
||||||
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public function getResource(string $name): Resource
|
public function getResource(string $name): Resource
|
||||||
{
|
{
|
||||||
$resource_name = sprintf('@%s:%s', PackageDirectory::RESOURCES, $name);
|
$resource_name = sprintf('@%s:%s', PackageDirectory::RESOURCES->value, $name);
|
||||||
if(!isset($this->headers[PackageStructure::DIRECTORY][$resource_name]))
|
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$resource_name]))
|
||||||
{
|
{
|
||||||
throw new ConfigurationException(sprintf('Resource \'%s\' not found in package', $name));
|
throw new ConfigurationException(sprintf('Resource \'%s\' not found in package \'%s\'', $name, $this->packagePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
return Resource::fromArray(ZiProto::decode($this->get($resource_name)));
|
return Resource::fromArray(ZiProto::decode($this->get($resource_name)));
|
||||||
}
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new IntegrityException(sprintf('Failed to decode resource \'%s\' from package \'%s\' using ZiProto: %s', $name, $this->packagePath, $e->getMessage()), $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a resource from the package by pointer
|
* Returns a resource from the package by pointer
|
||||||
|
@ -632,12 +748,19 @@
|
||||||
* @param int $pointer
|
* @param int $pointer
|
||||||
* @param int $length
|
* @param int $length
|
||||||
* @return Resource
|
* @return Resource
|
||||||
* @throws ConfigurationException
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public function getResourceByPointer(int $pointer, int $length): Resource
|
public function getResourceByPointer(int $pointer, int $length): Resource
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
return Resource::fromArray(ZiProto::decode($this->getByPointer($pointer, $length)));
|
return Resource::fromArray(ZiProto::decode($this->getByPointer($pointer, $length)));
|
||||||
}
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new IntegrityException(sprintf('Failed to decode resource from pointer \'%s\' with length \'%s\' from package \'%s\' using ZiProto: %s', $pointer, $length, $this->packagePath, $e->getMessage()), $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches the package's directory for a file that matches the given filename
|
* Searches the package's directory for a file that matches the given filename
|
||||||
|
@ -647,7 +770,7 @@
|
||||||
*/
|
*/
|
||||||
public function find(string $filename): string|false
|
public function find(string $filename): string|false
|
||||||
{
|
{
|
||||||
foreach($this->headers[PackageStructure::DIRECTORY] as $name => $location)
|
foreach($this->headers[PackageStructure::DIRECTORY->value] as $name => $location)
|
||||||
{
|
{
|
||||||
if(str_ends_with($name, $filename))
|
if(str_ends_with($name, $filename))
|
||||||
{
|
{
|
||||||
|
@ -665,7 +788,7 @@
|
||||||
*/
|
*/
|
||||||
public function getPackageOffset(): int
|
public function getPackageOffset(): int
|
||||||
{
|
{
|
||||||
return $this->package_offset;
|
return $this->packageOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -673,7 +796,7 @@
|
||||||
*/
|
*/
|
||||||
public function getPackageLength(): int
|
public function getPackageLength(): int
|
||||||
{
|
{
|
||||||
return $this->package_length;
|
return $this->packageLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -681,7 +804,7 @@
|
||||||
*/
|
*/
|
||||||
public function getHeaderOffset(): int
|
public function getHeaderOffset(): int
|
||||||
{
|
{
|
||||||
return $this->header_offset;
|
return $this->headerOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -689,7 +812,7 @@
|
||||||
*/
|
*/
|
||||||
public function getHeaderLength(): int
|
public function getHeaderLength(): int
|
||||||
{
|
{
|
||||||
return $this->header_length;
|
return $this->headerLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -697,7 +820,7 @@
|
||||||
*/
|
*/
|
||||||
public function getDataOffset(): int
|
public function getDataOffset(): int
|
||||||
{
|
{
|
||||||
return $this->data_offset;
|
return $this->dataOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -705,7 +828,7 @@
|
||||||
*/
|
*/
|
||||||
public function getDataLength(): int
|
public function getDataLength(): int
|
||||||
{
|
{
|
||||||
return $this->data_length;
|
return $this->dataLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -719,12 +842,12 @@
|
||||||
{
|
{
|
||||||
$checksum = hash($hash, '', $binary);
|
$checksum = hash($hash, '', $binary);
|
||||||
|
|
||||||
fseek($this->package_file, $this->package_offset);
|
fseek($this->packageFile, $this->packageOffset);
|
||||||
$bytes_left = $this->package_length;
|
$bytes_left = $this->packageLength;
|
||||||
|
|
||||||
while ($bytes_left > 0)
|
while ($bytes_left > 0)
|
||||||
{
|
{
|
||||||
$buffer = fread($this->package_file, min(1024, $bytes_left));
|
$buffer = fread($this->packageFile, min(1024, $bytes_left));
|
||||||
$buffer_length = strlen($buffer);
|
$buffer_length = strlen($buffer);
|
||||||
$bytes_left -= $buffer_length;
|
$bytes_left -= $buffer_length;
|
||||||
$checksum = hash($hash, ($checksum . $buffer), $binary);
|
$checksum = hash($hash, ($checksum . $buffer), $binary);
|
||||||
|
@ -752,13 +875,13 @@
|
||||||
throw new IOException(sprintf('Failed to open file \'%s\'', $path));
|
throw new IOException(sprintf('Failed to open file \'%s\'', $path));
|
||||||
}
|
}
|
||||||
|
|
||||||
fseek($this->package_file, $this->package_offset);
|
fseek($this->packageFile, $this->packageOffset);
|
||||||
$remaining_bytes = $this->package_length;
|
$remaining_bytes = $this->packageLength;
|
||||||
|
|
||||||
while ($remaining_bytes > 0)
|
while($remaining_bytes > 0)
|
||||||
{
|
{
|
||||||
$bytes_to_read = min($remaining_bytes, 4096);
|
$bytes_to_read = min($remaining_bytes, 4096);
|
||||||
$data = fread($this->package_file, $bytes_to_read);
|
$data = fread($this->packageFile, $bytes_to_read);
|
||||||
|
|
||||||
if ($data === false)
|
if ($data === false)
|
||||||
{
|
{
|
||||||
|
@ -788,9 +911,9 @@
|
||||||
*/
|
*/
|
||||||
public function __destruct()
|
public function __destruct()
|
||||||
{
|
{
|
||||||
if(is_resource($this->package_file))
|
if(is_resource($this->packageFile))
|
||||||
{
|
{
|
||||||
fclose($this->package_file);
|
fclose($this->packageFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
195
src/ncc/Classes/PackageWriter.php
Normal file → Executable file
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
namespace ncc\Classes;
|
namespace ncc\Classes;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
use ncc\Enums\Flags\PackageFlags;
|
use ncc\Enums\Flags\PackageFlags;
|
||||||
use ncc\Enums\PackageDirectory;
|
use ncc\Enums\PackageDirectory;
|
||||||
use ncc\Enums\PackageStructure;
|
use ncc\Enums\PackageStructure;
|
||||||
|
@ -52,70 +53,70 @@
|
||||||
/**
|
/**
|
||||||
* @var resource
|
* @var resource
|
||||||
*/
|
*/
|
||||||
private $temp_file;
|
private $tempFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var resource
|
* @var resource
|
||||||
*/
|
*/
|
||||||
private $package_file;
|
private $packageFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string;
|
* @var string;
|
||||||
*/
|
*/
|
||||||
private $temporary_path;
|
private $temporaryPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
private $data_written;
|
private $dataWritten;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PackageWriter constructor.
|
* PackageWriter constructor.
|
||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public function __construct(string $file_path, bool $overwrite=true)
|
public function __construct(string $filePath, bool $overwrite=true)
|
||||||
{
|
{
|
||||||
if(!$overwrite && is_file($file_path))
|
if(!$overwrite && is_file($filePath))
|
||||||
{
|
{
|
||||||
throw new IOException(sprintf('File \'%s\' already exists', $file_path));
|
throw new IOException(sprintf('File \'%s\' already exists', $filePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_file($file_path))
|
if(is_file($filePath))
|
||||||
{
|
{
|
||||||
unlink($file_path);
|
unlink($filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_file($file_path . '.tmp'))
|
if(is_file($filePath . '.tmp'))
|
||||||
{
|
{
|
||||||
unlink($file_path . '.tmp');
|
unlink($filePath . '.tmp');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the parent directory if it doesn't exist
|
// Create the parent directory if it doesn't exist
|
||||||
if(!is_dir(dirname($file_path)))
|
if(!is_dir(dirname($filePath)))
|
||||||
{
|
{
|
||||||
if (!mkdir($concurrentDirectory = dirname($file_path), 0777, true) && !is_dir($concurrentDirectory))
|
if (!mkdir($concurrentDirectory = dirname($filePath), 0777, true) && !is_dir($concurrentDirectory))
|
||||||
{
|
{
|
||||||
throw new IOException(sprintf('Directory "%s" was not created', $concurrentDirectory));
|
throw new IOException(sprintf('Directory "%s" was not created', $concurrentDirectory));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
touch($file_path);
|
touch($filePath);
|
||||||
touch($file_path . '.tmp');
|
touch($filePath . '.tmp');
|
||||||
|
|
||||||
$this->data_written = false;
|
$this->dataWritten = false;
|
||||||
$this->temporary_path = $file_path . '.tmp';
|
$this->temporaryPath = $filePath . '.tmp';
|
||||||
$this->temp_file = @fopen($this->temporary_path, 'wb'); // Create a temporary data file
|
$this->tempFile = @fopen($this->temporaryPath, 'wb'); // Create a temporary data file
|
||||||
$this->package_file = @fopen($file_path, 'wb');
|
$this->packageFile = @fopen($filePath, 'wb');
|
||||||
$this->headers = [
|
$this->headers = [
|
||||||
PackageStructure::FILE_VERSION => PackageStructureVersions::_2_0,
|
PackageStructure::FILE_VERSION->value => PackageStructureVersions::_2_0->value,
|
||||||
PackageStructure::FLAGS => [],
|
PackageStructure::FLAGS->value => [],
|
||||||
PackageStructure::DIRECTORY => []
|
PackageStructure::DIRECTORY->value => []
|
||||||
];
|
];
|
||||||
|
|
||||||
if($this->temp_file === false || $this->package_file === false)
|
if($this->tempFile === false || $this->packageFile === false)
|
||||||
{
|
{
|
||||||
throw new IOException(sprintf('Failed to open file \'%s\'', $file_path));
|
throw new IOException(sprintf('Failed to open file \'%s\'', $filePath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +127,7 @@
|
||||||
*/
|
*/
|
||||||
public function getFileVersion(): string
|
public function getFileVersion(): string
|
||||||
{
|
{
|
||||||
return (string)$this->headers[PackageStructure::FILE_VERSION];
|
return (string)$this->headers[PackageStructure::FILE_VERSION->value];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,7 +138,7 @@
|
||||||
*/
|
*/
|
||||||
public function setFileVersion(string $version): void
|
public function setFileVersion(string $version): void
|
||||||
{
|
{
|
||||||
$this->headers[PackageStructure::FILE_VERSION] = $version;
|
$this->headers[PackageStructure::FILE_VERSION->value] = $version;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,43 +148,64 @@
|
||||||
*/
|
*/
|
||||||
public function getFlags(): array
|
public function getFlags(): array
|
||||||
{
|
{
|
||||||
return (array)$this->headers[PackageStructure::FLAGS];
|
return (array)$this->headers[PackageStructure::FLAGS->value];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the package flags
|
* Sets the package flags
|
||||||
*
|
*
|
||||||
* @param array $flags
|
* @param string[]|PackageFlags[] $flags
|
||||||
* @return void
|
* @return void
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public function setFlags(array $flags): void
|
public function setFlags(array $flags): void
|
||||||
{
|
{
|
||||||
if($this->data_written)
|
if($this->dataWritten)
|
||||||
{
|
{
|
||||||
throw new IOException('Cannot set flags after data has been written to the package');
|
throw new IOException('Cannot set flags after data has been written to the package');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->headers[PackageStructure::FLAGS] = $flags;
|
foreach($flags as $flag)
|
||||||
|
{
|
||||||
|
if(is_string($flag))
|
||||||
|
{
|
||||||
|
$flag = PackageFlags::tryFrom($flag);
|
||||||
|
if($flag === null)
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException(sprintf('Unexpected flag: %s', $flag));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->headers[PackageStructure::FLAGS->value] = $flag->value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a flag to the package
|
* Adds a flag to the package
|
||||||
*
|
*
|
||||||
* @param string $flag
|
* @param PackageFlags|string $flag
|
||||||
* @return void
|
* @return void
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public function addFlag(string $flag): void
|
public function addFlag(PackageFlags|string $flag): void
|
||||||
{
|
{
|
||||||
if($this->data_written)
|
if(is_string($flag))
|
||||||
|
{
|
||||||
|
$flag = PackageFlags::tryFrom($flag);
|
||||||
|
if($flag === null)
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException(sprintf('Unexpected flag: %s', $flag));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->dataWritten)
|
||||||
{
|
{
|
||||||
throw new IOException('Cannot add a flag after data has been written to the package');
|
throw new IOException('Cannot add a flag after data has been written to the package');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!in_array($flag, $this->headers[PackageStructure::FLAGS], true))
|
if(!in_array($flag, $this->headers[PackageStructure::FLAGS->value], true))
|
||||||
{
|
{
|
||||||
$this->headers[PackageStructure::FLAGS][] = $flag;
|
$this->headers[PackageStructure::FLAGS->value][] = $flag->value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,14 +216,23 @@
|
||||||
* @return void
|
* @return void
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public function removeFlag(string $flag): void
|
public function removeFlag(PackageFlags|string $flag): void
|
||||||
{
|
{
|
||||||
if($this->data_written)
|
if(is_string($flag))
|
||||||
|
{
|
||||||
|
$flag = PackageFlags::tryFrom($flag);
|
||||||
|
if($flag === null)
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException(sprintf('Unexpected flag: %s', $flag));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->dataWritten)
|
||||||
{
|
{
|
||||||
throw new IOException('Cannot remove a flag after data has been written to the package');
|
throw new IOException('Cannot remove a flag after data has been written to the package');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->headers[PackageStructure::FLAGS] = array_diff($this->headers[PackageStructure::FLAGS], [$flag]);
|
$this->headers[PackageStructure::FLAGS->value] = array_diff($this->headers[PackageStructure::FLAGS->value], [$flag->value]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -213,22 +244,22 @@
|
||||||
*/
|
*/
|
||||||
public function add(string $name, string $data): array
|
public function add(string $name, string $data): array
|
||||||
{
|
{
|
||||||
if(isset($this->headers[PackageStructure::DIRECTORY][$name]))
|
if(isset($this->headers[PackageStructure::DIRECTORY->value][$name]))
|
||||||
{
|
{
|
||||||
return explode(':', $this->headers[PackageStructure::DIRECTORY][$name]);
|
return explode(':', $this->headers[PackageStructure::DIRECTORY->value][$name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(in_array(PackageFlags::COMPRESSION, $this->headers[PackageStructure::FLAGS], true))
|
if(in_array(PackageFlags::COMPRESSION->value, $this->headers[PackageStructure::FLAGS->value], true))
|
||||||
{
|
{
|
||||||
if(in_array(PackageFlags::LOW_COMPRESSION, $this->headers[PackageStructure::FLAGS], true))
|
if(in_array(PackageFlags::LOW_COMPRESSION->value, $this->headers[PackageStructure::FLAGS->value], true))
|
||||||
{
|
{
|
||||||
$data = gzcompress($data, 1);
|
$data = gzcompress($data, 1);
|
||||||
}
|
}
|
||||||
else if(in_array(PackageFlags::MEDIUM_COMPRESSION, $this->headers[PackageStructure::FLAGS], true))
|
else if(in_array(PackageFlags::MEDIUM_COMPRESSION->value, $this->headers[PackageStructure::FLAGS->value], true))
|
||||||
{
|
{
|
||||||
$data = gzcompress($data, 6);
|
$data = gzcompress($data, 6);
|
||||||
}
|
}
|
||||||
else if(in_array(PackageFlags::HIGH_COMPRESSION, $this->headers[PackageStructure::FLAGS], true))
|
else if(in_array(PackageFlags::HIGH_COMPRESSION->value, $this->headers[PackageStructure::FLAGS->value], true))
|
||||||
{
|
{
|
||||||
$data = gzcompress($data, 9);
|
$data = gzcompress($data, 9);
|
||||||
}
|
}
|
||||||
|
@ -238,10 +269,10 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$pointer = sprintf("%d:%d", ftell($this->temp_file), strlen($data));
|
$pointer = sprintf("%d:%d", ftell($this->tempFile), strlen($data));
|
||||||
$this->headers[PackageStructure::DIRECTORY][$name] = $pointer;
|
$this->headers[PackageStructure::DIRECTORY->value][$name] = $pointer;
|
||||||
$this->data_written = true;
|
$this->dataWritten = true;
|
||||||
fwrite($this->temp_file, $data);
|
fwrite($this->tempFile, $data);
|
||||||
|
|
||||||
return explode(':', $pointer);
|
return explode(':', $pointer);
|
||||||
}
|
}
|
||||||
|
@ -256,12 +287,12 @@
|
||||||
*/
|
*/
|
||||||
public function addPointer(string $name, int $offset, int $length): void
|
public function addPointer(string $name, int $offset, int $length): void
|
||||||
{
|
{
|
||||||
if(isset($this->headers[PackageStructure::DIRECTORY][$name]))
|
if(isset($this->headers[PackageStructure::DIRECTORY->value][$name]))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->headers[PackageStructure::DIRECTORY][$name] = sprintf("%d:%d", $offset, $length);
|
$this->headers[PackageStructure::DIRECTORY->value][$name] = sprintf("%d:%d", $offset, $length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -272,7 +303,7 @@
|
||||||
*/
|
*/
|
||||||
public function setAssembly(Assembly $assembly): array
|
public function setAssembly(Assembly $assembly): array
|
||||||
{
|
{
|
||||||
return $this->add(sprintf('@%s', PackageDirectory::ASSEMBLY), ZiProto::encode($assembly->toArray(true)));
|
return $this->add(sprintf('@%s', PackageDirectory::ASSEMBLY->value), ZiProto::encode($assembly->toArray(true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -283,7 +314,7 @@
|
||||||
*/
|
*/
|
||||||
public function setMetadata(Metadata $metadata): array
|
public function setMetadata(Metadata $metadata): array
|
||||||
{
|
{
|
||||||
return $this->add(sprintf('@%s', PackageDirectory::METADATA), ZiProto::encode($metadata->toArray(true)));
|
return $this->add(sprintf('@%s', PackageDirectory::METADATA->value), ZiProto::encode($metadata->toArray(true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -294,7 +325,7 @@
|
||||||
*/
|
*/
|
||||||
public function setInstaller(Installer $installer): array
|
public function setInstaller(Installer $installer): array
|
||||||
{
|
{
|
||||||
return $this->add(sprintf('@%s', PackageDirectory::INSTALLER), ZiProto::encode($installer->toArray(true)));
|
return $this->add(sprintf('@%s', PackageDirectory::INSTALLER->value), ZiProto::encode($installer->toArray(true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -305,7 +336,7 @@
|
||||||
*/
|
*/
|
||||||
public function addDependencyConfiguration(Dependency $dependency): array
|
public function addDependencyConfiguration(Dependency $dependency): array
|
||||||
{
|
{
|
||||||
return $this->add(sprintf('@%s:%s', PackageDirectory::DEPENDENCIES, $dependency->getName()), ZiProto::encode($dependency->toArray(true)));
|
return $this->add(sprintf('@%s:%s', PackageDirectory::DEPENDENCIES->value, $dependency->getName()), ZiProto::encode($dependency->toArray(true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -316,7 +347,7 @@
|
||||||
*/
|
*/
|
||||||
public function addExecutionUnit(ExecutionUnit $unit): array
|
public function addExecutionUnit(ExecutionUnit $unit): array
|
||||||
{
|
{
|
||||||
return $this->add(sprintf('@%s:%s', PackageDirectory::EXECUTION_UNITS, $unit->getExecutionPolicy()->getName()), ZiProto::encode($unit->toArray(true)));
|
return $this->add(sprintf('@%s:%s', PackageDirectory::EXECUTION_UNITS->value, $unit->getExecutionPolicy()->getName()), ZiProto::encode($unit->toArray(true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -327,7 +358,7 @@
|
||||||
*/
|
*/
|
||||||
public function addComponent(Component $component): array
|
public function addComponent(Component $component): array
|
||||||
{
|
{
|
||||||
return $this->add(sprintf('@%s:%s', PackageDirectory::COMPONENTS, $component->getName()), ZiProto::encode($component->toArray(true)));
|
return $this->add(sprintf('@%s:%s', PackageDirectory::COMPONENTS->value, $component->getName()), ZiProto::encode($component->toArray(true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -338,7 +369,7 @@
|
||||||
*/
|
*/
|
||||||
public function addResource(Resource $resource): array
|
public function addResource(Resource $resource): array
|
||||||
{
|
{
|
||||||
return $this->add(sprintf('@%s:%s', PackageDirectory::RESOURCES, $resource->getName()), ZiProto::encode($resource->toArray(true)));
|
return $this->add(sprintf('@%s:%s', PackageDirectory::RESOURCES->value, $resource->getName()), ZiProto::encode($resource->toArray(true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -351,7 +382,7 @@
|
||||||
*/
|
*/
|
||||||
public function mapClass(string $class, int $offset, int $length): void
|
public function mapClass(string $class, int $offset, int $length): void
|
||||||
{
|
{
|
||||||
$this->addPointer(sprintf('@%s:%s', PackageDirectory::CLASS_POINTER, $class), $offset, $length);
|
$this->addPointer(sprintf('@%s:%s', PackageDirectory::CLASS_POINTER->value, $class), $offset, $length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -364,7 +395,7 @@
|
||||||
public function merge(PackageReader $reader): void
|
public function merge(PackageReader $reader): void
|
||||||
{
|
{
|
||||||
$progress_bar = new ConsoleProgressBar(sprintf('Merging %s', $reader->getAssembly()->getPackage()), count($reader->getDirectory()));
|
$progress_bar = new ConsoleProgressBar(sprintf('Merging %s', $reader->getAssembly()->getPackage()), count($reader->getDirectory()));
|
||||||
$processed_resources = [];
|
$processedResources = [];
|
||||||
|
|
||||||
foreach($reader->getDirectory() as $name => $pointer)
|
foreach($reader->getDirectory() as $name => $pointer)
|
||||||
{
|
{
|
||||||
|
@ -372,23 +403,23 @@
|
||||||
|
|
||||||
switch((int)substr(explode(':', $name, 2)[0], 1))
|
switch((int)substr(explode(':', $name, 2)[0], 1))
|
||||||
{
|
{
|
||||||
case PackageDirectory::METADATA:
|
case PackageDirectory::METADATA->value:
|
||||||
case PackageDirectory::ASSEMBLY:
|
case PackageDirectory::ASSEMBLY->value:
|
||||||
case PackageDirectory::INSTALLER:
|
case PackageDirectory::INSTALLER->value:
|
||||||
case PackageDirectory::EXECUTION_UNITS:
|
case PackageDirectory::EXECUTION_UNITS->value:
|
||||||
Console::outDebug(sprintf('Skipping %s', $name));
|
Console::outDebug(sprintf('Skipping %s', $name));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if(isset($processed_resources[$pointer]))
|
if(isset($processedResources[$pointer]))
|
||||||
{
|
{
|
||||||
Console::outDebug(sprintf('Merging %s as a pointer', $name));
|
Console::outDebug(sprintf('Merging %s as a pointer', $name));
|
||||||
$this->addPointer($name, (int)$processed_resources[$pointer][0], (int)$processed_resources[$pointer][1]);
|
$this->addPointer($name, (int)$processedResources[$pointer][0], (int)$processedResources[$pointer][1]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Console::outDebug(sprintf('Merging %s', $name));
|
Console::outDebug(sprintf('Merging %s', $name));
|
||||||
$processed_resources[$pointer] = $this->add($name, $reader->get($name));
|
$processedResources[$pointer] = $this->add($name, $reader->get($name));
|
||||||
}
|
}
|
||||||
|
|
||||||
$progress_bar->increaseValue(1, true);
|
$progress_bar->increaseValue(1, true);
|
||||||
|
@ -406,34 +437,34 @@
|
||||||
*/
|
*/
|
||||||
public function close(): void
|
public function close(): void
|
||||||
{
|
{
|
||||||
if(!is_resource($this->package_file) || !is_resource($this->temp_file))
|
if(!is_resource($this->packageFile) || !is_resource($this->tempFile))
|
||||||
{
|
{
|
||||||
throw new IOException('Package is already closed');
|
throw new IOException('Package is already closed');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the temporary data file
|
// Close the temporary data file
|
||||||
fclose($this->temp_file);
|
fclose($this->tempFile);
|
||||||
|
|
||||||
// Write the magic bytes "ncc_pkg" to the package and the header
|
// Write the magic bytes "ncc_pkg" to the package and the header
|
||||||
fwrite($this->package_file, 'ncc_pkg');
|
fwrite($this->packageFile, 'ncc_pkg');
|
||||||
fwrite($this->package_file, ZiProto::encode($this->headers));
|
fwrite($this->packageFile, ZiProto::encode($this->headers));
|
||||||
fwrite($this->package_file, "\x1F\x1F\x1F\x1F");
|
fwrite($this->packageFile, "\x1F\x1F\x1F\x1F");
|
||||||
|
|
||||||
// Copy the temporary data file to the package
|
// Copy the temporary data file to the package
|
||||||
$temp_file = fopen($this->temporary_path, 'rb');
|
$temp_file = fopen($this->temporaryPath, 'rb');
|
||||||
stream_copy_to_stream($temp_file, $this->package_file);
|
stream_copy_to_stream($temp_file, $this->packageFile);
|
||||||
|
|
||||||
// End the package by writing the end-of-package delimiter (0xFFAA55F0)
|
// End the package by writing the end-of-package delimiter (0xFFAA55F0)
|
||||||
fwrite($this->package_file, "\xFF\xAA\x55\xF0");
|
fwrite($this->packageFile, "\xFF\xAA\x55\xF0");
|
||||||
|
|
||||||
// Close the file handles
|
// Close the file handles
|
||||||
fclose($this->package_file);
|
fclose($this->packageFile);
|
||||||
fclose($temp_file);
|
fclose($temp_file);
|
||||||
|
|
||||||
unlink($this->temporary_path);
|
unlink($this->temporaryPath);
|
||||||
|
|
||||||
$this->package_file = null;
|
$this->packageFile = null;
|
||||||
$this->temp_file = null;
|
$this->tempFile = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -451,14 +482,14 @@
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if(is_resource($this->package_file))
|
if(is_resource($this->packageFile))
|
||||||
{
|
{
|
||||||
fclose($this->package_file);
|
fclose($this->packageFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_resource($this->temp_file))
|
if(is_resource($this->tempFile))
|
||||||
{
|
{
|
||||||
fclose($this->temp_file);
|
fclose($this->tempFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|