summaryrefslogtreecommitdiff
path: root/ext/zip
diff options
context:
space:
mode:
authorHannes Magnusson <bjori@php.net>2007-08-06 22:02:32 +0000
committerHannes Magnusson <bjori@php.net>2007-08-06 22:02:32 +0000
commit42e003cd6c4c726c4f0117f6a19f4af02a964323 (patch)
treeb85cbfd3952a8b0f5ae601c0f71d2ea9c0a7133b /ext/zip
parenta289952c471c669b0accdec1a77d9b803eeec983 (diff)
downloadphp-git-42e003cd6c4c726c4f0117f6a19f4af02a964323.tar.gz
MFH: - Fix isset/empty($ZipArchive->property)
MFH: - Add test
Diffstat (limited to 'ext/zip')
-rw-r--r--ext/zip/php_zip.c50
-rw-r--r--ext/zip/tests/oo_properties.phpt59
2 files changed, 109 insertions, 0 deletions
diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c
index ec25cc6efc..59336158de 100644
--- a/ext/zip/php_zip.c
+++ b/ext/zip/php_zip.c
@@ -449,6 +449,55 @@ static zval* php_zip_read_property(zval *object, zval *member, int type TSRMLS_D
}
/* }}} */
+static int php_zip_has_property(zval *object, zval *member, int type TSRMLS_DC) /* {{{ */
+{
+ ze_zip_object *obj;
+ zval tmp_member;
+ zip_prop_handler *hnd;
+ zend_object_handlers *std_hnd;
+ int ret, retval = 0;
+
+ if (member->type != IS_STRING) {
+ tmp_member = *member;
+ zval_copy_ctor(&tmp_member);
+ convert_to_string(&tmp_member);
+ member = &tmp_member;
+ }
+
+ ret = FAILURE;
+ obj = (ze_zip_object *)zend_objects_get_address(object TSRMLS_CC);
+
+ if (obj->prop_handler != NULL) {
+ ret = zend_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
+ }
+
+ if (ret == SUCCESS) {
+ zval *tmp;
+
+ if (type == 2) {
+ retval = 1;
+ } else if (php_zip_property_reader(obj, hnd, &tmp, 1 TSRMLS_CC) == SUCCESS) {
+ tmp->refcount = 1;
+ tmp->is_ref = 0;
+ if (type == 1) {
+ retval = zend_is_true(tmp);
+ } else if (type == 0) {
+ retval = (Z_TYPE_P(tmp) != IS_NULL);
+ }
+ zval_ptr_dtor(&tmp);
+ }
+ } else {
+ std_hnd = zend_get_std_object_handlers();
+ retval = std_hnd->has_property(object, member, type TSRMLS_CC);
+ }
+
+ if (member == &tmp_member) {
+ zval_dtor(member);
+ }
+ return retval;
+}
+/* }}} */
+
static HashTable *php_zip_get_properties(zval *object TSRMLS_DC)/* {{{ */
{
ze_zip_object *obj;
@@ -1965,6 +2014,7 @@ static PHP_MINIT_FUNCTION(zip)
zip_object_handlers.get_properties = php_zip_get_properties;
zip_object_handlers.read_property = php_zip_read_property;
+ zip_object_handlers.has_property = php_zip_has_property;
INIT_CLASS_ENTRY(ce, "ZipArchive", zip_class_functions);
ce.create_object = php_zip_object_new;
diff --git a/ext/zip/tests/oo_properties.phpt b/ext/zip/tests/oo_properties.phpt
new file mode 100644
index 0000000000..cc7cecae84
--- /dev/null
+++ b/ext/zip/tests/oo_properties.phpt
@@ -0,0 +1,59 @@
+--TEST--
+ziparchive::properties isset()/empty() checks
+--SKIPIF--
+<?php
+/* $Id$ */
+if(!extension_loaded('zip')) die('skip');
+?>
+--FILE--
+<?php
+
+$dirname = dirname(__FILE__) . '/';
+$file = $dirname . '__property_test.zip';
+
+copy($dirname . 'test_with_comment.zip', $file);
+
+$zip = new ZipArchive;
+if (!$zip->open($file)) {
+ exit('failed');
+}
+
+printf("zip->status (%d):\n\tempty(): %d\n\tisset(): %d\n", $zip->status, empty($zip->status), isset($zip->status));
+printf("zip->numFiles (%d):\n\tempty(): %d\n\tisset(): %d\n", $zip->numFiles, empty($zip->numFiles), isset($zip->numFiles));
+printf("zip->bogus (%d):\n\tempty(): %d\n\tisset(): %d\n", $zip->bogus, empty($zip->bogus), isset($zip->bogus));
+
+
+$zip->addEmptyDir('emptydir');
+
+printf("zip->status (%d):\n\tempty(): %d\n\tisset(): %d\n", $zip->status, empty($zip->status), isset($zip->status));
+printf("zip->numFiles (%d):\n\tempty(): %d\n\tisset(): %d\n", $zip->numFiles, empty($zip->numFiles), isset($zip->numFiles));
+printf("zip->filename (%d):\n\tempty(): %d\n\tisset(): %d\n", strlen($zip->filename), empty($zip->filename), isset($zip->filename));
+printf("zip->comment (%d):\n\tempty(): %d\n\tisset(): %d\n", strlen($zip->comment), empty($zip->comment), isset($zip->comment));
+
+var_dump(unlink($file));
+?>
+--EXPECTF--
+zip->status (0):
+ empty(): 1
+ isset(): 1
+zip->numFiles (4):
+ empty(): 0
+ isset(): 1
+
+Notice: Undefined property: ZipArchive::$bogus in %s on line %d
+zip->bogus (0):
+ empty(): 1
+ isset(): 0
+zip->status (0):
+ empty(): 1
+ isset(): 1
+zip->numFiles (5):
+ empty(): 0
+ isset(): 1
+zip->filename (0):
+ empty(): 1
+ isset(): 1
+zip->comment (19):
+ empty(): 0
+ isset(): 1
+