From dcf3ff8c41ee243487ede709a3b6f48ba433d3cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ewilan=20Rivi=C3=A8re?= Date: Fri, 8 Mar 2024 12:59:43 +0100 Subject: [PATCH 1/5] Update description to include EPUB and CBA support --- README.md | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index de58793..c97d52d 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ [![tests][tests-src]][tests-href] [![codecov][codecov-src]][codecov-href] -PHP package to handle archives (`.zip`, `.rar`, `.tar`, `.7z`, `.pdf`) with unified API and hybrid solution (native/`p7zip`), designed to works with eBooks (`.epub`, `.cbz`, `.cbr`, `.cb7`, `.cbt`). +PHP package to handle archives (`.zip`, `.rar`, `.tar`, `.7z`, `.pdf`) with unified API and hybrid solution (native/`p7zip`), designed to works with EPUB and CBA (`.cbz`, `.cbr`, `.cb7`, `.cbt`). Supports Linux, macOS and Windows. diff --git a/composer.json b/composer.json index 239263b..36c9c56 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "kiwilan/php-archive", "version": "2.2.0", - "description": "PHP package to handle archives (.zip, .rar, .tar, .7z, .pdf) with unified API and hybrid solution (native/p7zip), designed to works with eBooks (.epub, .cbz, .cbr, .cb7, .cbt).", + "description": "PHP package to handle archives (.zip, .rar, .tar, .7z, .pdf) with unified API and hybrid solution (native/p7zip), designed to works with EPUB and CBA (.cbz, .cbr, .cb7, .cbt).", "keywords": [ "php", "archive", From c3153e389e0fd676c9f91ecf74aebb089ac5f60f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ewilan=20Rivi=C3=A8re?= Date: Fri, 8 Mar 2024 13:05:08 +0100 Subject: [PATCH 2/5] Add 7z installation command to macOS workflow --- .github/workflows/run-macos.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/run-macos.yml b/.github/workflows/run-macos.yml index 15a1808..9f38dbd 100644 --- a/.github/workflows/run-macos.yml +++ b/.github/workflows/run-macos.yml @@ -19,6 +19,7 @@ jobs: brew install rar brew install ghostscript brew install imagemagick + which 7z shell: bash - name: Setup PHP From 45596622f993e09efe329714bad49d09ffcf7d8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ewilan=20Rivi=C3=A8re?= Date: Fri, 8 Mar 2024 16:14:17 +0100 Subject: [PATCH 3/5] Add 7z path check in macOS workflow --- .github/workflows/run-macos.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/run-macos.yml b/.github/workflows/run-macos.yml index 9f38dbd..d6974c1 100644 --- a/.github/workflows/run-macos.yml +++ b/.github/workflows/run-macos.yml @@ -19,6 +19,11 @@ jobs: brew install rar brew install ghostscript brew install imagemagick + shell: bash + + - name: Check 7z path + continue-on-error: true + run: | which 7z shell: bash From f48ef8a78ae2138e13de5a77c3d30dca4a3d6797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ewilan=20Rivi=C3=A8re?= Date: Fri, 8 Mar 2024 16:43:53 +0100 Subject: [PATCH 4/5] Add .env file creation step in GitHub workflows --- .env.example | 3 ++ .github/workflows/run-macos.yml | 5 +++ .github/workflows/run-tests-pz7ip.yml | 5 +++ .github/workflows/run-tests.yml | 5 +++ .github/workflows/run-windows.yml | 5 +++ .gitignore | 1 + tests/ArchiveTest.php | 9 +---- tests/Pest.php | 50 +++++++++++++++++++++++++++ 8 files changed, 75 insertions(+), 8 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..788cf54 --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +SEVEN_ZIP_BINARY_PATH_LINUX=/usr/bin/7z +SEVEN_ZIP_BINARY_PATH_WINDOWS=C:\Users\runneradmin\scoop\apps\7zip\current\7z.exe +SEVEN_ZIP_BINARY_PATH_MACOS=/usr/local/bin/7z diff --git a/.github/workflows/run-macos.yml b/.github/workflows/run-macos.yml index d6974c1..c3a59c3 100644 --- a/.github/workflows/run-macos.yml +++ b/.github/workflows/run-macos.yml @@ -55,6 +55,11 @@ jobs: sudo cp ./modules/rar.so $pecl_path sudo echo "extension=rar.so" > $phpini_path + - name: Create .env file + run: | + cp .env.example .env + shell: bash + - name: Check extension rar run: php -m | grep rar diff --git a/.github/workflows/run-tests-pz7ip.yml b/.github/workflows/run-tests-pz7ip.yml index 6d11e6b..954e35a 100644 --- a/.github/workflows/run-tests-pz7ip.yml +++ b/.github/workflows/run-tests-pz7ip.yml @@ -31,6 +31,11 @@ jobs: - name: Install dependencies run: composer update --prefer-dist --no-interaction + - name: Create .env file + run: | + cp .env.example .env + shell: bash + - name: Check extension imagick run: php -m | grep imagick diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index f0817c7..3f7e8fc 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -55,6 +55,11 @@ jobs: sudo cp ./modules/rar.so $pecl_path sudo echo "extension=rar.so" > $phpini_path + - name: Create .env file + run: | + cp .env.example .env + shell: bash + - name: Check extension rar run: php -m | grep rar diff --git a/.github/workflows/run-windows.yml b/.github/workflows/run-windows.yml index f0fbf55..ae968bf 100644 --- a/.github/workflows/run-windows.yml +++ b/.github/workflows/run-windows.yml @@ -47,6 +47,11 @@ jobs: - name: Install dependencies run: composer update --prefer-dist --no-interaction + - name: Create .env file + run: | + cp .env.example .env + shell: powershell + # - name: Check extension rar # run: php -m | grep rar diff --git a/.gitignore b/.gitignore index 9985a12..79ede7e 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ example temp CHANGELOG-draft.md .phpunit.cache +.env diff --git a/tests/ArchiveTest.php b/tests/ArchiveTest.php index a60c007..2c54ac6 100644 --- a/tests/ArchiveTest.php +++ b/tests/ArchiveTest.php @@ -159,14 +159,7 @@ function (Pest\Expectation $item) use ($ext) { })->with([ZIP_PASSWORD, RAR_PASSWORD, SEVENZIP_PASSWORD, TAR_PASSWORD]); it('can handle archive with binary path', function (string $path) { - if (PHP_OS_FAMILY === 'Windows') { - $current_user = exec('echo %USERNAME%'); - $binary_path = "C:\\Users\\{$current_user}\\scoop\\apps\\7zip\\current\\7z.exe"; - } elseif (PHP_OS_FAMILY === 'Darwin') { - $binary_path = '/opt/homebrew/bin/7z'; - } else { - $binary_path = '/usr/bin/7z'; - } + $binary_path = getSevenZipBinaryPath(); $archive = Archive::read($path)->overrideBinaryPath($binary_path); $files = $archive->getFileItems(); diff --git a/tests/Pest.php b/tests/Pest.php index 0d5d468..e0f1bc4 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -179,3 +179,53 @@ function recurseRmdir(string $dir) } // rmdir($dir); } + +function dotenv(): array +{ + $path = __DIR__.'/../'; + $lines = file($path.'.env'); + $dotenv = []; + + foreach ($lines as $line) { + if (! empty($line)) { + $data = explode('=', $line); + $key = $data[0]; + if ($key === " \n ") { + continue; + } + unset($data[0]); + $value = implode('=', $data); + + $key = $key ? trim($key) : ''; + $value = $value ? trim($value) : ''; + + if ($key === '') { + continue; + } + + $value = str_replace('"', '', $value); + $value = str_replace("'", '', $value); + + $dotenv[$key] = $value; + } + } + + return $dotenv; +} + +function getDotenv(string $key): string +{ + return dotenv()[$key] ?? ''; +} + +function getSevenZipBinaryPath(): string +{ + $os = PHP_OS_FAMILY; + $dotenv = match ($os) { + 'Windows' => 'SEVEN_ZIP_BINARY_PATH_WINDOWS', + 'Darwin' => 'SEVEN_ZIP_BINARY_PATH_MACOS', + default => 'SEVEN_ZIP_BINARY_PATH_LINUX', + }; + + return getDotenv($dotenv); +} From 7114592bd61984b5ad8a6f7e79131e6dcff8d535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ewilan=20Rivi=C3=A8re?= Date: Wed, 20 Mar 2024 13:53:48 +0100 Subject: [PATCH 5/5] v2.3.0 - Add password option for ZIP, RAR and 7z files, using `read(string $path, ?string $password = null)` and `readFromString(string $contents, ?string $password = null, ?string $extension = null)` methods. - Add new `Archive::class` method `readFromString(string $contents, ?string $password = null, ?string $extension = null)` to read an archive from a string - When you read RAR or 7z archives with `p7zip` binary, you can set manually the path to the binary using `overrideBinaryPath(string $path)` method. - `getFiles()` method is now deprecated. Use `getFileItems()` instead. - New method `getFileItem(string $path)` to get a single file item. --- .github/workflows/run-macos.yml | 6 ------ composer.json | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/run-macos.yml b/.github/workflows/run-macos.yml index c3a59c3..2ad8178 100644 --- a/.github/workflows/run-macos.yml +++ b/.github/workflows/run-macos.yml @@ -21,12 +21,6 @@ jobs: brew install imagemagick shell: bash - - name: Check 7z path - continue-on-error: true - run: | - which 7z - shell: bash - - name: Setup PHP uses: shivammathur/setup-php@v2 with: diff --git a/composer.json b/composer.json index 36c9c56..86e2a84 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "kiwilan/php-archive", - "version": "2.2.0", + "version": "2.3.0", "description": "PHP package to handle archives (.zip, .rar, .tar, .7z, .pdf) with unified API and hybrid solution (native/p7zip), designed to works with EPUB and CBA (.cbz, .cbr, .cb7, .cbt).", "keywords": [ "php",