1
0
mirror of https://github.com/Ne-Lexa/php-zip.git synced 2025-01-17 20:58:22 +01:00

Rename methods removePassword*() to disableEncryption*()

This commit is contained in:
Ne-Lexa 2017-11-14 14:47:46 +03:00
parent e62e51efb5
commit d32b000855
8 changed files with 45 additions and 38 deletions

View File

@ -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).
#### <a name="Documentation-Open-Zip-Archive"></a> Создание/Открытие ZIP-архива
@ -678,15 +678,15 @@ $zipFile->setPasswordEntry($entryName, $password);
$encryptionMethod = ZipFile::ENCRYPTION_METHOD_WINZIP_AES_256;
$zipFile->setPasswordEntry($entryName, $password, $encryptionMethod);
```
<a name="Documentation-ZipFile-removePassword"></a> **ZipFile::removePassword** - удаляет пароль у всех файлов в архиве.
<a name="Documentation-ZipFile-disableEncryption"></a> **ZipFile::disableEncryption** - отключает шифрования всех записей, находящихся в архиве.
> _Обратите внимание, что действие данного метода не распространяется на записи, добавленные после выполнения этого метода._
```php
$zipFile->removePassword();
$zipFile->disableEncryption();
```
<a name="Documentation-ZipFile-removePasswordEntry"></a> **ZipFile::removePasswordEntry** - удаляет пароль у конкретного файла в архиве.
<a name="Documentation-ZipFile-disableEncryptionEntry"></a> **ZipFile::disableEncryptionEntry** - отключает шифрование записи по её имени.
```php
$zipFile->removePasswordEntry($entryName);
$zipFile->disableEncryptionEntry($entryName);
```
#### <a name="Documentation-ZipAlign-Usage"></a> zipalign
<a name="Documentation-ZipFile-setZipAlign"></a> **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`.

View File

@ -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.
#### <a name="Documentation-Open-Zip-Archive"></a> 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);
```
<a name="Documentation-ZipFile-removePassword"></a> **ZipFile::removePassword** - removes the password from all files in the archive.
<a name="Documentation-ZipFile-disableEncryption"></a> **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();
```
<a name="Documentation-ZipFile-removePasswordEntry"></a> **ZipFile::removePasswordEntry** - removes password from one entry in the archive.
<a name="Documentation-ZipFile-disableEncryptionEntry"></a> **ZipFile::disableEncryptionEntry** - disable encryption of an entry defined by its name.
```php
$zipFile->removePasswordEntry($entryName);
$zipFile->disableEncryptionEntry($entryName);
```
#### <a name="Documentation-ZipAlign-Usage"></a> zipalign
<a name="Documentation-ZipFile-setZipAlign"></a> **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`.

View File

@ -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;
}

View File

@ -252,7 +252,7 @@ interface ZipEntry
*
* @return ZipEntry
*/
public function clearEncryption();
public function disableEncryption();
/**
* Returns the compression method for this entry.

View File

@ -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);

View File

@ -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;

View File

@ -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

View File

@ -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());