Skip to content

Commit b5638a1

Browse files
committed
zip extension version 1.22.0 for libzip 1.10.0
- add new error macros (ER_DATA_LENGTH and ER_NOT_ALLOWED) - add new archive global flags (ER_AFL_*) - add ZipArchive::setArchiveFlag and ZipArchive::getArchiveFlag methods New methods are available since libzip 0.11, but really usable with new global flags
1 parent dda42be commit b5638a1

File tree

5 files changed

+191
-2
lines changed

5 files changed

+191
-2
lines changed

ext/zip/php_zip.c

+34
Original file line numberDiff line numberDiff line change
@@ -2097,6 +2097,40 @@ PHP_METHOD(ZipArchive, getArchiveComment)
20972097
}
20982098
/* }}} */
20992099

2100+
PHP_METHOD(ZipArchive, setArchiveFlag)
2101+
{
2102+
struct zip *intern;
2103+
zval *self = ZEND_THIS;
2104+
zend_long flag, value;
2105+
2106+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &flag, &value) == FAILURE) {
2107+
RETURN_THROWS();
2108+
}
2109+
2110+
ZIP_FROM_OBJECT(intern, self);
2111+
2112+
if (zip_set_archive_flag(intern, flag, (int)value)) {
2113+
RETURN_FALSE;
2114+
} else {
2115+
RETURN_TRUE;
2116+
}
2117+
}
2118+
2119+
PHP_METHOD(ZipArchive, getArchiveFlag)
2120+
{
2121+
struct zip *intern;
2122+
zval *self = ZEND_THIS;
2123+
zend_long flag, flags = 0;
2124+
2125+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l", &flag, &flags) == FAILURE) {
2126+
RETURN_THROWS();
2127+
}
2128+
2129+
ZIP_FROM_OBJECT(intern, self);
2130+
2131+
RETURN_LONG(zip_get_archive_flag(intern, flag, flags));
2132+
}
2133+
21002134
/* {{{ Set or remove (NULL/'') the comment of an entry using its Name */
21012135
PHP_METHOD(ZipArchive, setCommentName)
21022136
{

ext/zip/php_zip.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extern zend_module_entry zip_module_entry;
3131
#define ZIP_OVERWRITE ZIP_TRUNCATE
3232
#endif
3333

34-
#define PHP_ZIP_VERSION "1.21.1"
34+
#define PHP_ZIP_VERSION "1.22.0"
3535

3636
#ifdef HAVE_LIBZIP_VERSION
3737
#define LIBZIP_VERSION_STR zip_libzip_version()

ext/zip/php_zip.stub.php

+54
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,56 @@ class ZipArchive implements Countable
492492
public const ER_CANCELLED = UNKNOWN;
493493
#endif
494494

495+
/* since 1.10.0 */
496+
#ifdef ZIP_ER_DATA_LENGTH
497+
/**
498+
* N Unexpected length of data
499+
* @var int
500+
* @cvalue ZIP_ER_DATA_LENGTH
501+
*/
502+
public const ER_DATA_LENGTH = UNKNOWN;
503+
#endif
504+
#ifdef ZIP_ER_NOT_ALLOWED
505+
/**
506+
* Not allowed in torrentzip
507+
* @var int
508+
* @cvalue ZIP_ER_NOT_ALLOWED
509+
*/
510+
public const ER_NOT_ALLOWED = UNKNOWN;
511+
#endif
512+
#ifdef ZIP_AFL_RDONLY
513+
/**
514+
* read only -- cannot be cleared
515+
* @var int
516+
* @cvalue ZIP_AFL_RDONLY
517+
*/
518+
public const AFL_RDONLY = UNKNOWN;
519+
#endif
520+
#ifdef ZIP_AFL_IS_TORRENTZIP
521+
/**
522+
* current archive is torrentzipped
523+
* @var int
524+
* @cvalue ZIP_AFL_IS_TORRENTZIP
525+
*/
526+
public const AFL_IS_TORRENTZIP = UNKNOWN;
527+
#endif
528+
#ifdef ZIP_AFL_WANT_TORRENTZIP
529+
/**
530+
* write archive in torrentzip format
531+
* @var int
532+
* @cvalue ZIP_AFL_WANT_TORRENTZIP
533+
*/
534+
public const AFL_WANT_TORRENTZIP = UNKNOWN;
535+
#endif
536+
#ifdef ZIP_AFL_CREATE_OR_KEEP_FILE_FOR_EMPTY_ARCHIVE
537+
/**
538+
* don't remove file if archive is empty
539+
* @var int
540+
* @cvalue ZIP_AFL_CREATE_OR_KEEP_FILE_FOR_EMPTY_ARCHIVE
541+
*/
542+
public const AFL_CREATE_OR_KEEP_FILE_FOR_EMPTY_ARCHIVE = UNKNOWN;
543+
#endif
544+
495545
#ifdef ZIP_OPSYS_DEFAULT
496546
/**
497547
* @var int
@@ -722,6 +772,10 @@ public function setArchiveComment(string $comment): bool {}
722772
/** @tentative-return-type */
723773
public function getArchiveComment(int $flags = 0): string|false {}
724774

775+
public function setArchiveFlag(int $flag, int $value): bool {}
776+
777+
public function getArchiveFlag(int $flag, int $flags = 0): int {}
778+
725779
/** @tentative-return-type */
726780
public function setCommentIndex(int $index, string $comment): bool {}
727781

ext/zip/php_zip_arginfo.h

+63-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/zip/tests/oo_archive_flag.phpt

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
ZipArchive::getArchiveFlag and setArchiveFlag
3+
--EXTENSIONS--
4+
zip
5+
--SKIPIF--
6+
<?php
7+
if(version_compare(ZipArchive::LIBZIP_VERSION, '1.10.0', '<')) die('skip libzip < 1.10.0');?>
8+
--FILE--
9+
<?php
10+
$zip = new ZipArchive();
11+
12+
echo "Open write\n";
13+
$zip->open(__DIR__ . "/test.zip");
14+
var_dump($zip->getArchiveFlag(ZipArchive::AFL_RDONLY));
15+
var_dump($zip->setArchiveFlag(ZipArchive::AFL_RDONLY, 1), $zip->status === ZipArchive::ER_OK);
16+
var_dump($zip->getArchiveFlag(ZipArchive::AFL_RDONLY));
17+
$zip->close();
18+
19+
echo "\nOpen read\n";
20+
$zip->open(__DIR__ . "/test.zip", ZipArchive::RDONLY);
21+
var_dump($zip->getArchiveFlag(ZipArchive::AFL_RDONLY));
22+
var_dump($zip->setArchiveFlag(ZipArchive::AFL_RDONLY, 0), $zip->status !== ZipArchive::ER_OK);
23+
var_dump($zip->getArchiveFlag(ZipArchive::AFL_RDONLY));
24+
$zip->close();
25+
26+
27+
?>
28+
--EXPECTF--
29+
Open write
30+
int(0)
31+
bool(true)
32+
bool(true)
33+
int(1)
34+
35+
Open read
36+
int(1)
37+
bool(false)
38+
bool(true)
39+
int(1)

0 commit comments

Comments
 (0)