Skip to content

Commit 569d164

Browse files
committed
ZipArchive implements countable, added ZipArchive::count() method
1 parent 161c378 commit 569d164

File tree

5 files changed

+60
-1
lines changed

5 files changed

+60
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ PHP NEWS
4949
. Fixed bug #74883 (SQLite3::__construct() produces "out of memory" exception
5050
with invalid flags). (Anatol)
5151

52+
- ZIP:
53+
. ZipArchive implements countable, added ZipArchive::count() method. (Remi)
54+
5255
06 Jul 2017, PHP 7.2.0alpha3
5356

5457
- Core:

UPGRADING

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ PHP 7.2 UPGRADE NOTES
143143
ZipArchive::EM_AES_192
144144
ZipArchive::EM_AES_256
145145
. accept 'password' from zip stream context
146+
. ZipArchive implements countable, added ZipArchive::count() method.
147+
146148

147149
========================================
148150
3. Changes in SAPI modules

ext/zip/php_zip.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
#include "ext/standard/php_string.h"
2929
#include "ext/pcre/php_pcre.h"
3030
#include "ext/standard/php_filestat.h"
31+
#if PHP_VERSION_ID >= 70200
32+
#include "zend_interfaces.h"
33+
#elif defined(HAVE_SPL)
34+
#include "ext/spl/spl_iterators.h"
35+
#endif
3136
#include "php_zip.h"
3237

3338
/* zip_open is a macro for renaming libzip zipopen, so we need to use PHP_NAMED_FUNCTION */
@@ -1548,6 +1553,23 @@ static ZIPARCHIVE_METHOD(close)
15481553
}
15491554
/* }}} */
15501555

1556+
/* {{{ proto bool ZipArchive::count()
1557+
close the zip archive */
1558+
static ZIPARCHIVE_METHOD(count)
1559+
{
1560+
struct zip *intern;
1561+
zval *self = getThis();
1562+
1563+
if (!self) {
1564+
RETURN_FALSE;
1565+
}
1566+
1567+
ZIP_FROM_OBJECT(intern, self);
1568+
1569+
RETVAL_LONG(zip_get_num_files(intern));
1570+
}
1571+
/* }}} */
1572+
15511573
/* {{{ proto string ZipArchive::getStatusString()
15521574
* Returns the status error message, system and/or zip messages */
15531575
static ZIPARCHIVE_METHOD(getStatusString)
@@ -3069,6 +3091,7 @@ static const zend_function_entry zip_class_functions[] = {
30693091
ZIPARCHIVE_ME(open, arginfo_ziparchive_open, ZEND_ACC_PUBLIC)
30703092
ZIPARCHIVE_ME(setPassword, arginfo_ziparchive_setpassword, ZEND_ACC_PUBLIC)
30713093
ZIPARCHIVE_ME(close, arginfo_ziparchive__void, ZEND_ACC_PUBLIC)
3094+
ZIPARCHIVE_ME(count, arginfo_ziparchive__void, ZEND_ACC_PUBLIC)
30723095
ZIPARCHIVE_ME(getStatusString, arginfo_ziparchive__void, ZEND_ACC_PUBLIC)
30733096
ZIPARCHIVE_ME(addEmptyDir, arginfo_ziparchive_addemptydir, ZEND_ACC_PUBLIC)
30743097
ZIPARCHIVE_ME(addFromString, arginfo_ziparchive_addfromstring, ZEND_ACC_PUBLIC)
@@ -3141,6 +3164,11 @@ static PHP_MINIT_FUNCTION(zip)
31413164
php_zip_register_prop_handler(&zip_prop_handlers, "numFiles", php_zip_get_num_files, NULL, NULL, IS_LONG);
31423165
php_zip_register_prop_handler(&zip_prop_handlers, "filename", NULL, NULL, php_zipobj_get_filename, IS_STRING);
31433166
php_zip_register_prop_handler(&zip_prop_handlers, "comment", NULL, php_zipobj_get_zip_comment, NULL, IS_STRING);
3167+
#if PHP_VERSION_ID >= 70200
3168+
zend_class_implements(zip_class_entry, 1, zend_ce_countable);
3169+
#elif defined(HAVE_SPL)
3170+
zend_class_implements(zip_class_entry, 1, spl_ce_Countable);
3171+
#endif
31443172

31453173
REGISTER_ZIP_CLASS_CONST_LONG("CREATE", ZIP_CREATE);
31463174
REGISTER_ZIP_CLASS_CONST_LONG("EXCL", ZIP_EXCL);

ext/zip/php_zip.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extern zend_module_entry zip_module_entry;
3737
#define ZIP_OVERWRITE ZIP_TRUNCATE
3838
#endif
3939

40-
#define PHP_ZIP_VERSION "1.14.0"
40+
#define PHP_ZIP_VERSION "1.15.0"
4141

4242
#define ZIP_OPENBASEDIR_CHECKPATH(filename) php_check_open_basedir(filename)
4343

ext/zip/tests/oo_count.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
ziparchive::count()
3+
--SKIPIF--
4+
<?php
5+
/* $Id$ */
6+
if(!extension_loaded('zip')) die('skip');
7+
?>
8+
--FILE--
9+
<?php
10+
11+
$dirname = dirname(__FILE__) . '/';
12+
$file = $dirname . 'test.zip';
13+
14+
$zip = new ZipArchive;
15+
if (!$zip->open($file)) {
16+
exit('failed');
17+
}
18+
19+
var_dump($zip->numFiles, count($zip), $zip->numFiles == count($zip));
20+
?>
21+
Done
22+
--EXPECTF--
23+
int(4)
24+
int(4)
25+
bool(true)
26+
Done

0 commit comments

Comments
 (0)