1
0
mirror of https://github.com/Ne-Lexa/php-zip.git synced 2025-08-05 23:17:24 +02:00
This commit is contained in:
wapplay
2018-10-09 10:17:54 +03:00
parent f9e6a73587
commit e1866215a6
11 changed files with 24 additions and 14 deletions

View File

@@ -21,6 +21,7 @@
}
],
"require": {
"ext-zlib": "*",
"php": "^5.5 || ^7.0",
"psr/http-message": "^1.0"
},

View File

@@ -179,9 +179,11 @@ class WinZipAesEngine implements ZipEncryptionEngine
{
if (extension_loaded("openssl")) {
$numBits = strlen($key) * 8;
/** @noinspection PhpComposerExtensionStubsInspection */
return openssl_encrypt($data, 'AES-' . $numBits . '-CTR', $key, OPENSSL_RAW_DATA, $iv);
} elseif (extension_loaded("mcrypt")) {
/** @noinspection PhpDeprecationInspection */
/** @noinspection PhpComposerExtensionStubsInspection */
return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, "ctr", $iv);
} else {
throw new RuntimeException('Extension openssl or mcrypt not loaded');
@@ -200,9 +202,11 @@ class WinZipAesEngine implements ZipEncryptionEngine
{
if (extension_loaded("openssl")) {
$numBits = strlen($key) * 8;
/** @noinspection PhpComposerExtensionStubsInspection */
return openssl_decrypt($data, 'AES-' . $numBits . '-CTR', $key, OPENSSL_RAW_DATA, $iv);
} elseif (extension_loaded("mcrypt")) {
/** @noinspection PhpDeprecationInspection */
/** @noinspection PhpComposerExtensionStubsInspection */
return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $data, "ctr", $iv);
} else {
throw new RuntimeException('Extension openssl or mcrypt not loaded');
@@ -220,7 +224,7 @@ class WinZipAesEngine implements ZipEncryptionEngine
{
// Init key strength.
$password = $this->entry->getPassword();
if ($password === null){
if ($password === null) {
throw new ZipException('No password was set for the entry "'.$this->entry->getName().'"');
}

View File

@@ -152,7 +152,7 @@ class ExtraFieldsCollection implements \Countable, \ArrayAccess, \Iterator
public function offsetSet($offset, $value)
{
if ($value instanceof ExtraField) {
if ($offset !== $value::getHeaderId()){
if ($offset !== $value::getHeaderId()) {
throw new InvalidArgumentException("Value header id !== array access key");
}
$this->add($value);

View File

@@ -48,6 +48,7 @@ class ZipChangesEntry extends ZipAbstractEntry
* Returns an string content of the given entry.
*
* @return null|string
* @throws ZipException
*/
public function getEntryContent()
{

View File

@@ -57,7 +57,6 @@ class ZipSourceEntry extends ZipAbstractEntry
* Returns an string content of the given entry.
*
* @return string
* @throws ZipException
*/
public function getEntryContent()
{
@@ -74,7 +73,7 @@ class ZipSourceEntry extends ZipAbstractEntry
}
if (is_resource($this->entryContent)) {
rewind($this->entryContent);
return stream_get_contents($this->entryContent, -1, 0);
return stream_get_contents($this->entryContent);
}
return $this->entryContent;
}

View File

@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpMissingBreakStatementInspection */
namespace PhpZip\Model;
@@ -233,8 +233,6 @@ class ZipInfo
$xattr = (($externalAttributes >> 16) & 0xFFFF);
switch ($entry->getPlatform()) {
case self::MADE_BY_MS_DOS:
// no break
/** @noinspection PhpMissingBreakStatementInspection */
case self::MADE_BY_WINDOWS_NTFS:
if ($entry->getPlatform() != self::MADE_BY_MS_DOS ||
($xattr & 0700) !=

View File

@@ -446,6 +446,7 @@ class ZipInputStream implements ZipInputStreamInterface
if (!extension_loaded('bz2')) {
throw new ZipException('Extension bzip2 not install');
}
/** @noinspection PhpComposerExtensionStubsInspection */
$content = bzdecompress($content);
break;
default:
@@ -552,7 +553,7 @@ class ZipInputStream implements ZipInputStreamInterface
// skip source extraLength from input stream
fseek($this->in, $sourceExtraLength, SEEK_CUR);
} else {
$copyInToOutLength += ZipEntry::LOCAL_FILE_HEADER_MIN_LEN + $sourceExtraLength + $nameLength;;
$copyInToOutLength += ZipEntry::LOCAL_FILE_HEADER_MIN_LEN + $sourceExtraLength + $nameLength;
}
if ($entry->getGeneralPurposeBitFlag(ZipEntry::GPBF_DATA_DESCRIPTOR)) {
// crc-32 4 bytes

View File

@@ -255,6 +255,7 @@ class ZipOutputStream implements ZipOutputStreamInterface
$compressionLevel = $entry->getCompressionLevel() === ZipFileInterface::LEVEL_DEFAULT_COMPRESSION ?
ZipEntry::LEVEL_DEFAULT_BZIP2_COMPRESSION :
$entry->getCompressionLevel();
/** @noinspection PhpComposerExtensionStubsInspection */
$entryContent = bzcompress($entryContent, $compressionLevel);
if (is_int($entryContent)) {
throw new ZipException('Error bzip2 compress. Error code: ' . $entryContent);

View File

@@ -26,9 +26,11 @@ class CryptoUtil
throw new \RuntimeException("Could not generate a random string.");
}
} elseif (function_exists('openssl_random_pseudo_bytes')) {
/** @noinspection PhpComposerExtensionStubsInspection */
return openssl_random_pseudo_bytes($length);
} elseif (function_exists('mcrypt_create_iv')) {
/** @noinspection PhpDeprecationInspection */
/** @noinspection PhpComposerExtensionStubsInspection */
return mcrypt_create_iv($length);
} else {
throw new RuntimeException('Extension openssl or mcrypt not loaded');

View File

@@ -423,6 +423,7 @@ class ZipFile implements ZipFileInterface
if ($compressionMethod === null) {
if (function_exists('mime_content_type')) {
/** @noinspection PhpComposerExtensionStubsInspection */
$mimeType = @mime_content_type($filename);
$type = strtok($mimeType, '/');
if ($type === 'image') {
@@ -611,8 +612,7 @@ class ZipFile implements ZipFileInterface
\Iterator $iterator,
$localPath = '/',
$compressionMethod = null
)
{
) {
$localPath = (string)$localPath;
if (strlen($localPath) !== 0) {
$localPath = trim($localPath, '\\/');
@@ -696,8 +696,7 @@ class ZipFile implements ZipFileInterface
$localPath = '/',
$recursive = true,
$compressionMethod = null
)
{
) {
$inputDir = (string)$inputDir;
if (strlen($inputDir) === 0) {
throw new InvalidArgumentException('Input dir empty');
@@ -793,8 +792,7 @@ class ZipFile implements ZipFileInterface
$localPath = "/",
$recursive = true,
$compressionMethod = null
)
{
) {
$regexPattern = (string)$regexPattern;
if (empty($regexPattern)) {
throw new InvalidArgumentException("regex pattern empty");

View File

@@ -33,6 +33,7 @@ class ZipFileTest extends ZipTestCase
*/
public function testOpenFileCantOpen()
{
/** @noinspection PhpComposerExtensionStubsInspection */
if (0 === posix_getuid()) {
$this->markTestSkipped('Skip the test for a user with root privileges');
}
@@ -152,6 +153,7 @@ class ZipFileTest extends ZipTestCase
if (!extension_loaded("gd")) {
$this->markTestSkipped('not extension gd');
}
/** @noinspection PhpComposerExtensionStubsInspection */
$zipFile->openFromStream(imagecreate(1, 1));
}
@@ -1057,6 +1059,7 @@ class ZipFileTest extends ZipTestCase
*/
public function testExtractFail3()
{
/** @noinspection PhpComposerExtensionStubsInspection */
if (0 === posix_getuid()) {
$this->markTestSkipped('Skip the test for a user with root privileges');
}
@@ -1275,6 +1278,7 @@ class ZipFileTest extends ZipTestCase
*/
public function testAddFileCantOpen()
{
/** @noinspection PhpComposerExtensionStubsInspection */
if (posix_getuid() === 0) {
$this->markTestSkipped('Skip the test for a user with root privileges');
}
@@ -1588,6 +1592,7 @@ class ZipFileTest extends ZipTestCase
*/
public function testSaveAsFileNotWritable()
{
/** @noinspection PhpComposerExtensionStubsInspection */
if (0 === posix_getuid()) {
$this->markTestSkipped('Skip the test for a user with root privileges');
}