From ab6d5468bb4194e094eabfad733182d6bd5c5110 Mon Sep 17 00:00:00 2001 From: wapmorgan Date: Sun, 25 Jun 2023 00:51:14 +0300 Subject: [PATCH] Check passing driver. --- src/UnifiedArchive.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/UnifiedArchive.php b/src/UnifiedArchive.php index e7ed208..00d3197 100644 --- a/src/UnifiedArchive.php +++ b/src/UnifiedArchive.php @@ -283,7 +283,7 @@ protected static function getCreationDriver($archiveFormat, $inString, $encrypte * @param string $format Archive type * @param string|null $password */ - public function __construct($fileName, $format, $abilities = [], $password = null) + public function __construct($fileName, $format, $abilities = [], $password = null, $driver = null) { if (empty($abilities)) { $abilities = [Abilities::OPEN]; @@ -291,17 +291,20 @@ public function __construct($fileName, $format, $abilities = [], $password = nul $abilities[] = Abilities::OPEN_ENCRYPTED; } } - $driver = Formats::getFormatDriver($format, $abilities); if ($driver === null) { - throw new UnsupportedArchiveException( - 'Format ' . $format . ' driver with abilities (' - . implode( - ', ', - array_map(function ($ability) { - return array_search($ability, Abilities::$abilitiesLabels); - }, $abilities) - ) - . ') is not found'); + $driver = Formats::getFormatDriver($format, $abilities); + if ($driver === null) { + throw new UnsupportedArchiveException( + 'Format ' . $format . ' driver with abilities (' + . implode( + ', ', + array_map(function ($ability) { + return array_search($ability, Abilities::$abilitiesLabels); + }, $abilities) + ) + . ') is not found' + ); + } } $this->format = $format;