mirror of
https://github.com/Ne-Lexa/php-zip.git
synced 2025-10-20 17:46:31 +02:00
Add ZipModel for all changes.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip\Util;
|
||||
|
||||
use PhpZip\Exception\RuntimeException;
|
||||
use PhpZip\Exception\ZipException;
|
||||
|
||||
/**
|
||||
* Crypto Utils
|
||||
@@ -17,7 +17,7 @@ class CryptoUtil
|
||||
* @return string
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public static final function randomBytes($length)
|
||||
final public static function randomBytes($length)
|
||||
{
|
||||
$length = (int)$length;
|
||||
if (function_exists('random_bytes')) {
|
||||
@@ -30,4 +30,4 @@ class CryptoUtil
|
||||
throw new RuntimeException('Extension openssl or mcrypt not loaded');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip\Util;
|
||||
|
||||
use PhpZip\Exception\ZipException;
|
||||
@@ -39,9 +40,9 @@ class DateTimeConverter
|
||||
|
||||
return mktime(
|
||||
($dosTime >> 11) & 0x1f, // hour
|
||||
($dosTime >> 5) & 0x3f, // minute
|
||||
2 * ($dosTime & 0x1f), // second
|
||||
($dosTime >> 21) & 0x0f, // month
|
||||
($dosTime >> 5) & 0x3f, // minute
|
||||
2 * ($dosTime & 0x1f), // second
|
||||
($dosTime >> 21) & 0x0f, // month
|
||||
($dosTime >> 16) & 0x1f, // day
|
||||
1980 + (($dosTime >> 25) & 0x7f) // year
|
||||
);
|
||||
@@ -74,4 +75,4 @@ class DateTimeConverter
|
||||
$date['mday'] << 16 | $date['hours'] << 11 |
|
||||
$date['minutes'] << 5 | $date['seconds'] >> 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip\Util;
|
||||
|
||||
use PhpZip\Util\Iterator\IgnoreFilesFilterIterator;
|
||||
@@ -60,7 +61,7 @@ class FilesUtil
|
||||
$inCurrent = 0;
|
||||
$chars = str_split($globPattern);
|
||||
$regexPattern = '';
|
||||
foreach ($chars AS $currentChar) {
|
||||
foreach ($chars as $currentChar) {
|
||||
switch ($currentChar) {
|
||||
case '*':
|
||||
$regexPattern .= ($escaping ? "\\*" : '.*');
|
||||
@@ -103,19 +104,21 @@ class FilesUtil
|
||||
if ($inCurrent > 0 && !$escaping) {
|
||||
$regexPattern .= ')';
|
||||
$inCurrent--;
|
||||
} else if ($escaping)
|
||||
} elseif ($escaping) {
|
||||
$regexPattern = "\\}";
|
||||
else
|
||||
} else {
|
||||
$regexPattern = "}";
|
||||
}
|
||||
$escaping = false;
|
||||
break;
|
||||
case ',':
|
||||
if ($inCurrent > 0 && !$escaping) {
|
||||
$regexPattern .= '|';
|
||||
} else if ($escaping)
|
||||
} elseif ($escaping) {
|
||||
$regexPattern .= "\\,";
|
||||
else
|
||||
} else {
|
||||
$regexPattern = ",";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$escaping = false;
|
||||
@@ -211,12 +214,15 @@ class FilesUtil
|
||||
*/
|
||||
public static function humanSize($size, $unit = null)
|
||||
{
|
||||
if (($unit === null && $size >= 1 << 30) || $unit === "GB")
|
||||
if (($unit === null && $size >= 1 << 30) || $unit === "GB") {
|
||||
return number_format($size / (1 << 30), 2) . "GB";
|
||||
if (($unit === null && $size >= 1 << 20) || $unit === "MB")
|
||||
}
|
||||
if (($unit === null && $size >= 1 << 20) || $unit === "MB") {
|
||||
return number_format($size / (1 << 20), 2) . "MB";
|
||||
if (($unit === null && $size >= 1 << 10) || $unit === "KB")
|
||||
}
|
||||
if (($unit === null && $size >= 1 << 10) || $unit === "KB") {
|
||||
return number_format($size / (1 << 10), 2) . "KB";
|
||||
}
|
||||
return number_format($size) . " bytes";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip\Util\Iterator;
|
||||
|
||||
use PhpZip\Util\StringUtil;
|
||||
@@ -44,7 +45,7 @@ class IgnoreFilesFilterIterator extends \FilterIterator
|
||||
foreach ($this->ignoreFiles as $ignoreFile) {
|
||||
// handler dir and sub dir
|
||||
if ($fileInfo->isDir()
|
||||
&& $ignoreFile[strlen($ignoreFile) - 1] === '/'
|
||||
&& StringUtil::endsWith($ignoreFile, '/')
|
||||
&& StringUtil::endsWith($pathname, substr($ignoreFile, 0, -1))
|
||||
) {
|
||||
return false;
|
||||
@@ -57,4 +58,4 @@ class IgnoreFilesFilterIterator extends \FilterIterator
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip\Util\Iterator;
|
||||
|
||||
use PhpZip\Util\StringUtil;
|
||||
@@ -66,4 +67,4 @@ class IgnoreFilesRecursiveFilterIterator extends \RecursiveFilterIterator
|
||||
{
|
||||
return new self($this->getInnerIterator()->getChildren(), $this->ignoreFiles);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip\Util;
|
||||
|
||||
use PhpZip\Exception\ZipException;
|
||||
@@ -39,10 +40,24 @@ class PackUtil
|
||||
public static function unpackLongLE($value)
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '5.6.3') >= 0) {
|
||||
return current(unpack('P', $value));
|
||||
return unpack('P', $value)[1];
|
||||
}
|
||||
$unpack = unpack('Va/Vb', $value);
|
||||
return $unpack['a'] + ($unpack['b'] << 32);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Cast to signed int 32-bit
|
||||
*
|
||||
* @param int $int
|
||||
* @return int
|
||||
*/
|
||||
public static function toSignedInt32($int)
|
||||
{
|
||||
$int = $int & 0xffffffff;
|
||||
if (PHP_INT_SIZE === 8 && ($int & 0x80000000)) {
|
||||
return $int - 0x100000000;
|
||||
}
|
||||
return $int;
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip\Util;
|
||||
|
||||
/**
|
||||
@@ -25,6 +26,6 @@ class StringUtil
|
||||
public static function endsWith($haystack, $needle)
|
||||
{
|
||||
return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0
|
||||
&& strpos($haystack, $needle, $temp) !== false);
|
||||
&& strpos($haystack, $needle, $temp) !== false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user