From 2e7ecc149cd4eb0dd92c0ed87c52e2966353e42a Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 13 Aug 2024 10:34:59 +0800 Subject: [PATCH] Extract chromedriver regardless of position in archive (#13) * Extract chromedriver regardless of position in archive Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki --------- Signed-off-by: Mior Muhammad Zaki Co-authored-by: Alex Leahy --- composer.json | 1 + src/UpdateCommand.php | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index eafd911..13a2386 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,7 @@ "composer-runtime-api": "^2.2", "composer/semver": "^1.5 || ^3.0", "guzzlehttp/guzzle": "^7.2", + "illuminate/support": ">=5.7.0", "symfony/console": "^4.3.4 || ^5.0 || ^6.0", "symfony/polyfill-ctype": "^1.9", "symfony/process": "^4.3.4 || ^5.0 || ^6.0" diff --git a/src/UpdateCommand.php b/src/UpdateCommand.php index 92ecb35..fdd9aab 100644 --- a/src/UpdateCommand.php +++ b/src/UpdateCommand.php @@ -3,6 +3,7 @@ namespace Orchestra\DuskUpdater; use Exception; +use Illuminate\Support\Str; use RuntimeException; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -91,25 +92,27 @@ protected function extract(string $version, string $archive): string throw new RuntimeException("Unable to extract {$archive} without --install-dir"); } + $binary = null; + $zip = new ZipArchive(); $zip->open($archive); $zip->extractTo($this->directory); - switch (true) { - case version_compare($version, '115.0', '<'): - $index = 0; - break; - case version_compare($version, '127.0', '<'): - $index = 1; + for ($fileIndex = 0; $fileIndex < $zip->numFiles; $fileIndex++) { + /** @var string $filename */ + $filename = $zip->getNameIndex($fileIndex); + + if (Str::startsWith(basename($filename), 'chromedriver')) { + $binary = $filename; + + $zip->extractTo($this->directory, $binary); + break; - default: - $index = 2; + } } - $binary = $zip->getNameIndex($index); - $zip->close(); unlink($archive);