Skip to content

Commit

Permalink
Merge pull request #47 from kiwilan/develop
Browse files Browse the repository at this point in the history
v2.3.0
  • Loading branch information
ewilan-riviere authored Mar 20, 2024
2 parents 90a21d1 + 7114592 commit 0d868c1
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions .github/workflows/run-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,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

Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/run-tests-pz7ip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/run-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ example
temp
CHANGELOG-draft.md
.phpunit.cache
.env
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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).",
"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",
"archive",
Expand Down
9 changes: 1 addition & 8 deletions tests/ArchiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
50 changes: 50 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 0d868c1

Please sign in to comment.