From d32b000855f8fd9ae58f5b2f31a98b2c59d6006f Mon Sep 17 00:00:00 2001 From: Ne-Lexa Date: Tue, 14 Nov 2017 14:47:46 +0300 Subject: [PATCH] Rename methods `removePassword*()` to `disableEncryption*()` --- README.RU.md | 16 ++++++++-------- README.md | 16 ++++++++-------- src/PhpZip/Model/Entry/ZipAbstractEntry.php | 4 ++-- src/PhpZip/Model/ZipEntry.php | 2 +- src/PhpZip/Model/ZipModel.php | 3 +++ src/PhpZip/ZipFile.php | 18 ++++++++++-------- src/PhpZip/ZipFileInterface.php | 16 +++++++++------- tests/PhpZip/ZipPasswordTest.php | 8 ++++---- 8 files changed, 45 insertions(+), 38 deletions(-) diff --git a/README.RU.md b/README.RU.md index a0e8a4f..379091c 100644 --- a/README.RU.md +++ b/README.RU.md @@ -119,6 +119,8 @@ $zipFile - [ZipFile::deleteFromGlob](#Documentation-ZipFile-deleteFromGlob) - удаляет записи в соответствии с glob шаблоном. - [ZipFile::deleteFromRegex](#Documentation-ZipFile-deleteFromRegex) - удаляет записи в соответствии с регулярным выражением. - [ZipFile::deleteAll](#Documentation-ZipFile-deleteAll) - удаляет все записи в ZIP-архиве. +- [ZipFile::disableEncryption](#Documentation-ZipFile-disableEncryption) - отключает шифрования всех записей, находящихся в архиве. +- [ZipFile::disableEncryptionEntry](#Documentation-ZipFile-disableEncryptionEntry) - отключает шифрование записи по её имени. - [ZipFile::extractTo](#Documentation-ZipFile-extractTo) - извлекает содержимое архива в заданную директорию. - [ZipFile::getAllInfo](#Documentation-ZipFile-getAllInfo) - возвращает подробную информацию обо всех записях в архиве. - [ZipFile::getArchiveComment](#Documentation-ZipFile-getArchiveComment) - возвращает комментарий ZIP-архива. @@ -135,8 +137,6 @@ $zipFile - [ZipFile::outputAsAttachment](#Documentation-ZipFile-outputAsAttachment) - выводит ZIP-архив в браузер. - [ZipFile::outputAsResponse](#Documentation-ZipFile-outputAsResponse) - выводит ZIP-архив, как Response PSR-7. - [ZipFile::outputAsString](#Documentation-ZipFile-outputAsString) - выводит ZIP-архив в виде строки. -- [ZipFile::removePassword](#Documentation-ZipFile-removePassword) - удаляет пароль у всех файлов в архиве. -- [ZipFile::removePasswordEntry](#Documentation-ZipFile-removePasswordEntry) - удаляет пароль у конкретного файла в архиве. - [ZipFile::rename](#Documentation-ZipFile-rename) - переименовывает запись по имени. - [ZipFile::rewrite](#Documentation-ZipFile-rewrite) - сохраняет изменения и заново открывает изменившийся архив. - [ZipFile::saveAsFile](#Documentation-ZipFile-saveAsFile) - сохраняет архив в файл. @@ -155,7 +155,7 @@ $zipFile - [ZipFile::unchangeAll](#Documentation-ZipFile-unchangeAll) - отменяет все изменения, сделанные в архиве. - [ZipFile::unchangeArchiveComment](#Documentation-ZipFile-unchangeArchiveComment) - отменяет изменения в комментарии к архиву. - [ZipFile::unchangeEntry](#Documentation-ZipFile-unchangeEntry) - отменяет изменения для конкретной записи архива. -- ~~ZipFile::withoutPassword~~ - устаревший метод (**deprecated**) используйте метод [ZipFile::removePassword](#Documentation-ZipFile-removePassword). +- ~~ZipFile::withoutPassword~~ - устаревший метод (**deprecated**) используйте метод [ZipFile::disableEncryption](#Documentation-ZipFile-disableEncryption). - ~~ZipFile::withReadPassword~~ - устаревший метод (**deprecated**) используйте метод [ZipFile::setReadPassword](#Documentation-ZipFile-setReadPassword). #### Создание/Открытие ZIP-архива @@ -678,15 +678,15 @@ $zipFile->setPasswordEntry($entryName, $password); $encryptionMethod = ZipFile::ENCRYPTION_METHOD_WINZIP_AES_256; $zipFile->setPasswordEntry($entryName, $password, $encryptionMethod); ``` - **ZipFile::removePassword** - удаляет пароль у всех файлов в архиве. + **ZipFile::disableEncryption** - отключает шифрования всех записей, находящихся в архиве. > _Обратите внимание, что действие данного метода не распространяется на записи, добавленные после выполнения этого метода._ ```php -$zipFile->removePassword(); +$zipFile->disableEncryption(); ``` - **ZipFile::removePasswordEntry** - удаляет пароль у конкретного файла в архиве. + **ZipFile::disableEncryptionEntry** - отключает шифрование записи по её имени. ```php -$zipFile->removePasswordEntry($entryName); +$zipFile->disableEncryptionEntry($entryName); ``` #### zipalign **ZipFile::setZipAlign** - устанавливает выравнивание архива для оптимизации APK файлов (Android packages). @@ -808,7 +808,7 @@ composer update nelexa/zip + `setLevel` в `setCompressionLevel` + `ZipFile::setPassword` в `ZipFile::withReadPassword` + `ZipOutputFile::setPassword` в `ZipFile::withNewPassword` - + `ZipOutputFile::removePasswordAllEntries` в `ZipFile::withoutPassword` + + `ZipOutputFile::disableEncryptionAllEntries` в `ZipFile::withoutPassword` + `ZipOutputFile::setComment` в `ZipFile::setArchiveComment` + `ZipFile::getComment` в `ZipFile::getArchiveComment` - Изменились сигнатуры для методов `addDir`, `addFilesFromGlob`, `addFilesFromRegex`. diff --git a/README.md b/README.md index 22ca737..eed4546 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,8 @@ Other examples can be found in the `tests/` folder - [ZipFile::deleteFromGlob](#Documentation-ZipFile-deleteFromGlob) - deletes a entries in the archive using glob pattern. - [ZipFile::deleteFromRegex](#Documentation-ZipFile-deleteFromRegex) - deletes a entries in the archive using PCRE pattern. - [ZipFile::deleteAll](#Documentation-ZipFile-deleteAll) - deletes all entries in the ZIP archive. +- [ZipFile::disableEncryption](#Documentation-ZipFile-disableEncryption) - disable encryption for all entries that are already in the archive. +- [ZipFile::disableEncryptionEntry](#Documentation-ZipFile-disableEncryptionEntry) - disable encryption of an entry defined by its name. - [ZipFile::extractTo](#Documentation-ZipFile-extractTo) - extract the archive contents. - [ZipFile::getAllInfo](#Documentation-ZipFile-getAllInfo) - returns detailed information about all entries in the archive. - [ZipFile::getArchiveComment](#Documentation-ZipFile-getArchiveComment) - returns the Zip archive comment. @@ -135,8 +137,6 @@ Other examples can be found in the `tests/` folder - [ZipFile::outputAsAttachment](#Documentation-ZipFile-outputAsAttachment) - outputs a ZIP-archive to the browser. - [ZipFile::outputAsResponse](#Documentation-ZipFile-outputAsResponse) - outputs a ZIP-archive as PSR-7 Response. - [ZipFile::outputAsString](#Documentation-ZipFile-outputAsString) - outputs a ZIP-archive as string. -- [ZipFile::removePassword](#Documentation-ZipFile-removePassword) - removes the password from all files in the archive. -- [ZipFile::removePasswordEntry](#Documentation-ZipFile-removePasswordEntry) - removes password from one entry in the archive. - [ZipFile::rename](#Documentation-ZipFile-rename) - renames an entry defined by its name. - [ZipFile::rewrite](#Documentation-ZipFile-rewrite) - save changes and re-open the changed archive. - [ZipFile::saveAsFile](#Documentation-ZipFile-saveAsFile) - saves the archive to a file. @@ -155,7 +155,7 @@ Other examples can be found in the `tests/` folder - [ZipFile::unchangeAll](#Documentation-ZipFile-unchangeAll) - undo all changes done in the archive. - [ZipFile::unchangeArchiveComment](#Documentation-ZipFile-unchangeArchiveComment) - undo changes to the archive comment. - [ZipFile::unchangeEntry](#Documentation-ZipFile-unchangeEntry) - undo changes of an entry defined by its name. -- ~~ZipFile::withoutPassword~~ - is an deprecated method, use the [ZipFile::removePassword](#Documentation-ZipFile-removePassword) method. +- ~~ZipFile::withoutPassword~~ - is an deprecated method, use the [ZipFile::disableEncryption](#Documentation-ZipFile-disableEncryption) method. - ~~ZipFile::withReadPassword~~ - is an deprecated method, use the [ZipFile::setReadPassword](#Documentation-ZipFile-setReadPassword) method. #### Creation/Opening of ZIP-archive @@ -680,15 +680,15 @@ You can set the encryption method: $encryptionMethod = ZipFile::ENCRYPTION_METHOD_WINZIP_AES_256; $zipFile->setPasswordEntry($entryName, $password, $encryptionMethod); ``` - **ZipFile::removePassword** - removes the password from all files in the archive. + **ZipFile::disableEncryption** - disable encryption for all entries that are already in the archive. > _Note that this method does not apply to entries that were added after this method was run._ ```php -$zipFile->removePassword(); +$zipFile->disableEncryption(); ``` - **ZipFile::removePasswordEntry** - removes password from one entry in the archive. + **ZipFile::disableEncryptionEntry** - disable encryption of an entry defined by its name. ```php -$zipFile->removePasswordEntry($entryName); +$zipFile->disableEncryptionEntry($entryName); ``` #### zipalign **ZipFile::setZipAlign** - sets the alignment of the archive to optimize APK files (Android packages). @@ -807,7 +807,7 @@ Update your code to work with the new version: + `setLevel` to `setCompressionLevel` + `ZipFile::setPassword` to `ZipFile::withReadPassword` + `ZipOutputFile::setPassword` to `ZipFile::withNewPassword` - + `ZipOutputFile::removePasswordAllEntries` to `ZipFile::withoutPassword` + + `ZipOutputFile::disableEncryptionAllEntries` to `ZipFile::withoutPassword` + `ZipOutputFile::setComment` to `ZipFile::setArchiveComment` + `ZipFile::getComment` to `ZipFile::getArchiveComment` - Changed signature for methods `addDir`, `addFilesFromGlob`, `addFilesFromRegex`. diff --git a/src/PhpZip/Model/Entry/ZipAbstractEntry.php b/src/PhpZip/Model/Entry/ZipAbstractEntry.php index 0825f19..396d234 100644 --- a/src/PhpZip/Model/Entry/ZipAbstractEntry.php +++ b/src/PhpZip/Model/Entry/ZipAbstractEntry.php @@ -395,7 +395,7 @@ abstract class ZipAbstractEntry implements ZipEntry * * @return ZipEntry */ - public function clearEncryption() + public function disableEncryption() { $this->setEncrypted(false); $headerId = WinZipAesEntryExtraField::getHeaderId(); @@ -722,7 +722,7 @@ abstract class ZipAbstractEntry implements ZipEntry if (!empty($this->password)) { $this->setEncrypted(true); } else { - $this->clearEncryption(); + $this->disableEncryption(); } return $this; } diff --git a/src/PhpZip/Model/ZipEntry.php b/src/PhpZip/Model/ZipEntry.php index 7f80995..37d54c3 100644 --- a/src/PhpZip/Model/ZipEntry.php +++ b/src/PhpZip/Model/ZipEntry.php @@ -252,7 +252,7 @@ interface ZipEntry * * @return ZipEntry */ - public function clearEncryption(); + public function disableEncryption(); /** * Returns the compression method for this entry. diff --git a/src/PhpZip/Model/ZipModel.php b/src/PhpZip/Model/ZipModel.php index c5866b2..9adcf4e 100644 --- a/src/PhpZip/Model/ZipModel.php +++ b/src/PhpZip/Model/ZipModel.php @@ -162,6 +162,9 @@ class ZipModel implements \Countable $this->matcher()->all()->setPassword(null); } + /** + * @param string|ZipEntry $entryName + */ public function removePasswordEntry($entryName) { $this->matcher()->add($entryName)->setPassword(null); diff --git a/src/PhpZip/ZipFile.php b/src/PhpZip/ZipFile.php index 403bcd3..483288a 100644 --- a/src/PhpZip/ZipFile.php +++ b/src/PhpZip/ZipFile.php @@ -1080,7 +1080,7 @@ class ZipFile implements ZipFileInterface } /** - * Set password for zip archive + * Sets a new password for all files in the archive. * * @param string $password * @param int|null $encryptionMethod Encryption method @@ -1100,8 +1100,10 @@ class ZipFile implements ZipFileInterface } /** + * Sets a new password of an entry defined by its name. + * * @param string $entryName - * @param string|null $password + * @param string $password * @param int|null $encryptionMethod * @return ZipFileInterface * @throws ZipException @@ -1120,29 +1122,29 @@ class ZipFile implements ZipFileInterface /** * Remove password for all entries for update. * @return ZipFileInterface - * @deprecated using ZipFileInterface::removePassword() + * @deprecated using ZipFileInterface::disableEncryption() */ public function withoutPassword() { - return $this->removePassword(); + return $this->disableEncryption(); } /** - * Remove password for all entries for update. + * Disable encryption for all entries that are already in the archive. * @return ZipFileInterface */ - public function removePassword() + public function disableEncryption() { $this->zipModel->removePassword(); return $this; } /** - * Remove password for concrete entry. + * Disable encryption of an entry defined by its name. * @param string $entryName * @return ZipFileInterface */ - public function removePasswordEntry($entryName) + public function disableEncryptionEntry($entryName) { $this->zipModel->removePasswordEntry($entryName); return $this; diff --git a/src/PhpZip/ZipFileInterface.php b/src/PhpZip/ZipFileInterface.php index 05d31e3..53ab761 100644 --- a/src/PhpZip/ZipFileInterface.php +++ b/src/PhpZip/ZipFileInterface.php @@ -513,7 +513,7 @@ interface ZipFileInterface extends \Countable, \ArrayAccess, \Iterator public function withNewPassword($password, $encryptionMethod = self::ENCRYPTION_METHOD_WINZIP_AES_256); /** - * Set password for zip archive + * Sets a new password for all files in the archive. * * @param string $password * @param int|null $encryptionMethod Encryption method @@ -522,32 +522,34 @@ interface ZipFileInterface extends \Countable, \ArrayAccess, \Iterator public function setPassword($password, $encryptionMethod = self::ENCRYPTION_METHOD_WINZIP_AES_256); /** + * Sets a new password of an entry defined by its name. + * * @param string $entryName * @param string $password * @param int|null $encryptionMethod - * @return mixed + * @return ZipFileInterface */ public function setPasswordEntry($entryName, $password, $encryptionMethod = null); /** * Remove password for all entries for update. * @return ZipFileInterface - * @deprecated using ZipFileInterface::removePassword() + * @deprecated using ZipFileInterface::disableEncryption() */ public function withoutPassword(); /** - * Remove password for all entries for update. + * Disable encryption for all entries that are already in the archive. * @return ZipFileInterface */ - public function removePassword(); + public function disableEncryption(); /** - * Remove password for concrete entry. + * Disable encryption of an entry defined by its name. * @param string $entryName * @return ZipFileInterface */ - public function removePasswordEntry($entryName); + public function disableEncryptionEntry($entryName); /** * Undo all changes done in the archive diff --git a/tests/PhpZip/ZipPasswordTest.php b/tests/PhpZip/ZipPasswordTest.php index d4503f3..ac96f10 100644 --- a/tests/PhpZip/ZipPasswordTest.php +++ b/tests/PhpZip/ZipPasswordTest.php @@ -21,7 +21,7 @@ class ZipPasswordTest extends ZipFileAddDirTest } $password = base64_encode(CryptoUtil::randomBytes(100)); - $badPassword = "sdgt43r23wefe"; + $badPassword = "bad password"; // create encryption password with ZipCrypto $zipFile = new ZipFile(); @@ -86,7 +86,7 @@ class ZipPasswordTest extends ZipFileAddDirTest // clear password $zipFile->addFromString('file1', ''); - $zipFile->removePassword(); + $zipFile->disableEncryption(); $zipFile->addFromString('file2', ''); $zipFile->saveAsFile($this->outputFilename); $zipFile->close(); @@ -286,10 +286,10 @@ class ZipPasswordTest extends ZipFileAddDirTest self::assertFalse($zipFile->getEntryInfo('file' . $i)->isEncrypted()); } } - $zipFile->removePasswordEntry('file3'); + $zipFile->disableEncryptionEntry('file3'); self::assertFalse($zipFile->getEntryInfo('file3')->isEncrypted()); self::asserttrue($zipFile->getEntryInfo('file2')->isEncrypted()); - $zipFile->removePassword(); + $zipFile->disableEncryption(); $infoList = $zipFile->getAllInfo(); array_walk($infoList, function (ZipInfo $zipInfo) { self::assertFalse($zipInfo->isEncrypted());