Skip to content

Commit

Permalink
add ZipArchive::LENGTH_TO_END and ZipArchive::LENGTH_UNCHECKED constants
Browse files Browse the repository at this point in the history
  • Loading branch information
remicollet committed Jul 28, 2023
1 parent 566cf37 commit 0893b4b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
2 changes: 2 additions & 0 deletions UPGRADING
Expand Up @@ -483,6 +483,8 @@ PHP 8.3 UPGRADE NOTES
. ZipArchive::AFL_WANT_TORRENTZIP (libzip >= 1.10)
. ZipArchive::AFL_CREATE_OR_KEEP_FILE_FOR_EMPTY_ARCHIVE (libzip >= 1.10)
. ZipArchive::FL_OPEN_FILE_NOW
. ZipArchive::LENGTH_TO_END as default value for addFile and replaceFile
. ZipArchive::LENGTH_UNCHECKED (libzip >= 1.10.1)

========================================
11. Changes to INI File Handling
Expand Down
5 changes: 5 additions & 0 deletions ext/zip/php_zip.h
Expand Up @@ -31,6 +31,11 @@ extern zend_module_entry zip_module_entry;
#define ZIP_OVERWRITE ZIP_TRUNCATE
#endif

/* since 1.10.1 */
#ifndef ZIP_LENGTH_TO_END
#define ZIP_LENGTH_TO_END 0
#endif

/* Additionnal flags not from libzip */
#define ZIP_FL_OPEN_FILE_NOW (1u<<30)

Expand Down
19 changes: 16 additions & 3 deletions ext/zip/php_zip.stub.php
Expand Up @@ -459,7 +459,6 @@ class ZipArchive implements Countable
public const ER_WRONGPASSWD = UNKNOWN;

/* since 1.0.0 */

#ifdef ZIP_ER_OPNOTSUPP
/**
* N Operation not supported
Expand Down Expand Up @@ -721,6 +720,20 @@ class ZipArchive implements Countable
*/
public const LIBZIP_VERSION = UNKNOWN;

/**
* @var int
* @cvalue ZIP_LENGTH_TO_END
*/
public const LENGTH_TO_END = UNKNOWN;
/* since 1.10.1 */
#ifdef ZIP_LENGTH_UNCHECKED
/**
* @var int
* @cvalue ZIP_LENGTH_UNCHECKED
*/
public const LENGTH_UNCHECKED = UNKNOWN;
#endif

/** @readonly */
public int $lastId;
/** @readonly */
Expand Down Expand Up @@ -760,10 +773,10 @@ public function addEmptyDir(string $dirname, int $flags = 0): bool {}
public function addFromString(string $name, string $content, int $flags = ZipArchive::FL_OVERWRITE): bool {}

/** @tentative-return-type */
public function addFile(string $filepath, string $entryname = "", int $start = 0, int $length = 0, int $flags = ZipArchive::FL_OVERWRITE): bool {}
public function addFile(string $filepath, string $entryname = "", int $start = 0, int $length = ZipArchive::LENGTH_TO_END, int $flags = ZipArchive::FL_OVERWRITE): bool {}

/** @tentative-return-type */
public function replaceFile(string $filepath, int $index, int $start = 0, int $length = 0, int $flags = 0): bool {}
public function replaceFile(string $filepath, int $index, int $start = 0, int $length = ZipArchive::LENGTH_TO_END, int $flags = 0): bool {}

/** @tentative-return-type */
public function addGlob(string $pattern, int $flags = 0, array $options = []): array|false {}
Expand Down
20 changes: 17 additions & 3 deletions ext/zip/php_zip_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ext/zip/tests/oo_addfile.phpt
Expand Up @@ -24,7 +24,7 @@ if (!$zip->addFile($dirname . 'utils.inc', 'mini.txt', 12, 34)) {
echo "failed\n";
}
var_dump($zip->lastId);
if (!$zip->addFile($dirname . 'utils.inc', 'other.txt', 0, 0, ZipArchive::FL_OPEN_FILE_NOW)) {
if (!$zip->addFile($dirname . 'utils.inc', 'other.txt', 0, ZipArchive::LENGTH_TO_END, ZipArchive::FL_OPEN_FILE_NOW)) {
echo "failed\n";
}
var_dump($zip->lastId);
Expand Down

0 comments on commit 0893b4b

Please sign in to comment.