From 0aee7cf70a287d3e901787be144b7ff5a1441701 Mon Sep 17 00:00:00 2001 From: Arnaud Le Blanc Date: Tue, 26 Jul 2022 20:44:00 +0200 Subject: [PATCH] Add private constructor on Metadata classes (#531) --- metadata.c | 2 +- metadata.stub.php | 3 ++ metadata_arginfo.h | 7 ++- metadata_broker.c | 2 +- metadata_broker.stub.php | 3 ++ metadata_broker_arginfo.h | 7 ++- metadata_broker_legacy_arginfo.h | 7 ++- metadata_collection.c | 2 +- metadata_collection.stub.php | 3 ++ metadata_collection_arginfo.h | 7 ++- metadata_collection_legacy_arginfo.h | 7 ++- metadata_legacy_arginfo.h | 7 ++- metadata_partition.c | 2 +- metadata_partition.stub.php | 3 ++ metadata_partition_arginfo.h | 7 ++- metadata_partition_legacy_arginfo.h | 7 ++- metadata_topic.c | 2 +- metadata_topic.stub.php | 3 ++ metadata_topic_arginfo.h | 7 ++- metadata_topic_legacy_arginfo.h | 7 ++- package.xml | 8 +++- php_rdkafka_priv.h | 2 +- tests/metadata_001.phpt | 41 ++++++++++++++++ tests/metadata_broker_001.phpt | 41 ++++++++++++++++ tests/metadata_collection_001.phpt | 48 +++++++++++++++++++ tests/metadata_partition_001.phpt | 41 ++++++++++++++++ tests/metadata_topic_001.phpt | 41 ++++++++++++++++ ...artition.phpt => topic_partition_001.phpt} | 2 +- tests/topic_partition_002.phpt | 39 +++++++++++++++ topic_partition.c | 2 +- 30 files changed, 341 insertions(+), 19 deletions(-) create mode 100644 tests/metadata_001.phpt create mode 100644 tests/metadata_broker_001.phpt create mode 100644 tests/metadata_collection_001.phpt create mode 100644 tests/metadata_partition_001.phpt create mode 100644 tests/metadata_topic_001.phpt rename tests/{topic_partition.phpt => topic_partition_001.phpt} (96%) create mode 100644 tests/topic_partition_002.phpt diff --git a/metadata.c b/metadata.c index 7d7eda46..4e382480 100644 --- a/metadata.c +++ b/metadata.c @@ -107,7 +107,7 @@ static HashTable *get_debug_info(Z_RDKAFKA_OBJ *object, int *is_temp) /* {{{ */ array_init(&ary); intern = rdkafka_get_debug_object(object_intern, object); - if (!intern) { + if (!intern || !intern->metadata) { return Z_ARRVAL(ary); } diff --git a/metadata.stub.php b/metadata.stub.php index 0a16c00f..43363180 100644 --- a/metadata.stub.php +++ b/metadata.stub.php @@ -10,6 +10,9 @@ class Metadata { + /** @implementation-alias RdKafka::__construct */ + private function __construct() {} + /** @tentative-return-type */ public function getOrigBrokerId(): int {} diff --git a/metadata_arginfo.h b/metadata_arginfo.h index 4bd05145..bd1bfbc5 100644 --- a/metadata_arginfo.h +++ b/metadata_arginfo.h @@ -1,5 +1,8 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 7bdf537cb18915955d6c3f1d4775dcc9fc43eb4a */ + * Stub hash: 6c980079f802be29ef2c30e235a6071f5c0d628c */ + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RdKafka_Metadata___construct, 0, 0, 0) +ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_RdKafka_Metadata_getOrigBrokerId, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -13,6 +16,7 @@ ZEND_END_ARG_INFO() #define arginfo_class_RdKafka_Metadata_getTopics arginfo_class_RdKafka_Metadata_getBrokers +ZEND_METHOD(RdKafka, __construct); ZEND_METHOD(RdKafka_Metadata, getOrigBrokerId); ZEND_METHOD(RdKafka_Metadata, getOrigBrokerName); ZEND_METHOD(RdKafka_Metadata, getBrokers); @@ -20,6 +24,7 @@ ZEND_METHOD(RdKafka_Metadata, getTopics); static const zend_function_entry class_RdKafka_Metadata_methods[] = { + ZEND_MALIAS(RdKafka, __construct, __construct, arginfo_class_RdKafka_Metadata___construct, ZEND_ACC_PRIVATE) ZEND_ME(RdKafka_Metadata, getOrigBrokerId, arginfo_class_RdKafka_Metadata_getOrigBrokerId, ZEND_ACC_PUBLIC) ZEND_ME(RdKafka_Metadata, getOrigBrokerName, arginfo_class_RdKafka_Metadata_getOrigBrokerName, ZEND_ACC_PUBLIC) ZEND_ME(RdKafka_Metadata, getBrokers, arginfo_class_RdKafka_Metadata_getBrokers, ZEND_ACC_PUBLIC) diff --git a/metadata_broker.c b/metadata_broker.c index d6c9473d..0edb0281 100644 --- a/metadata_broker.c +++ b/metadata_broker.c @@ -94,7 +94,7 @@ static HashTable *get_debug_info(Z_RDKAFKA_OBJ *object, int *is_temp) /* {{{ */ array_init(&ary); intern = rdkafka_get_debug_object(object_intern, object); - if (!intern) { + if (!intern || !intern->metadata_broker) { return Z_ARRVAL(ary); } diff --git a/metadata_broker.stub.php b/metadata_broker.stub.php index dfa245b9..46a9671e 100644 --- a/metadata_broker.stub.php +++ b/metadata_broker.stub.php @@ -10,6 +10,9 @@ class Broker { + /** @implementation-alias RdKafka::__construct */ + private function __construct() {} + /** @tentative-return-type */ public function getId(): int {} diff --git a/metadata_broker_arginfo.h b/metadata_broker_arginfo.h index bc410767..cd734d80 100644 --- a/metadata_broker_arginfo.h +++ b/metadata_broker_arginfo.h @@ -1,5 +1,8 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 53fa93c8908858d59ab75b39a77efdea9e843675 */ + * Stub hash: 74c6ee55c31bb86f5bcf71a46607f31688ce71dd */ + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RdKafka_Metadata_Broker___construct, 0, 0, 0) +ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_RdKafka_Metadata_Broker_getId, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -10,12 +13,14 @@ ZEND_END_ARG_INFO() #define arginfo_class_RdKafka_Metadata_Broker_getPort arginfo_class_RdKafka_Metadata_Broker_getId +ZEND_METHOD(RdKafka, __construct); ZEND_METHOD(RdKafka_Metadata_Broker, getId); ZEND_METHOD(RdKafka_Metadata_Broker, getHost); ZEND_METHOD(RdKafka_Metadata_Broker, getPort); static const zend_function_entry class_RdKafka_Metadata_Broker_methods[] = { + ZEND_MALIAS(RdKafka, __construct, __construct, arginfo_class_RdKafka_Metadata_Broker___construct, ZEND_ACC_PRIVATE) ZEND_ME(RdKafka_Metadata_Broker, getId, arginfo_class_RdKafka_Metadata_Broker_getId, ZEND_ACC_PUBLIC) ZEND_ME(RdKafka_Metadata_Broker, getHost, arginfo_class_RdKafka_Metadata_Broker_getHost, ZEND_ACC_PUBLIC) ZEND_ME(RdKafka_Metadata_Broker, getPort, arginfo_class_RdKafka_Metadata_Broker_getPort, ZEND_ACC_PUBLIC) diff --git a/metadata_broker_legacy_arginfo.h b/metadata_broker_legacy_arginfo.h index 6d239430..cd63fc09 100644 --- a/metadata_broker_legacy_arginfo.h +++ b/metadata_broker_legacy_arginfo.h @@ -1,5 +1,8 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 53fa93c8908858d59ab75b39a77efdea9e843675 */ + * Stub hash: 74c6ee55c31bb86f5bcf71a46607f31688ce71dd */ + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RdKafka_Metadata_Broker___construct, 0, 0, 0) +ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RdKafka_Metadata_Broker_getId, 0, 0, 0) ZEND_END_ARG_INFO() @@ -9,12 +12,14 @@ ZEND_END_ARG_INFO() #define arginfo_class_RdKafka_Metadata_Broker_getPort arginfo_class_RdKafka_Metadata_Broker_getId +ZEND_METHOD(RdKafka, __construct); ZEND_METHOD(RdKafka_Metadata_Broker, getId); ZEND_METHOD(RdKafka_Metadata_Broker, getHost); ZEND_METHOD(RdKafka_Metadata_Broker, getPort); static const zend_function_entry class_RdKafka_Metadata_Broker_methods[] = { + ZEND_MALIAS(RdKafka, __construct, __construct, arginfo_class_RdKafka_Metadata_Broker___construct, ZEND_ACC_PRIVATE) ZEND_ME(RdKafka_Metadata_Broker, getId, arginfo_class_RdKafka_Metadata_Broker_getId, ZEND_ACC_PUBLIC) ZEND_ME(RdKafka_Metadata_Broker, getHost, arginfo_class_RdKafka_Metadata_Broker_getHost, ZEND_ACC_PUBLIC) ZEND_ME(RdKafka_Metadata_Broker, getPort, arginfo_class_RdKafka_Metadata_Broker_getPort, ZEND_ACC_PUBLIC) diff --git a/metadata_collection.c b/metadata_collection.c index 54dddacd..79be380f 100644 --- a/metadata_collection.c +++ b/metadata_collection.c @@ -101,7 +101,7 @@ static HashTable *get_debug_info(Z_RDKAFKA_OBJ *object, int *is_temp) /* {{{ */ array_init(&ary); intern = rdkafka_get_debug_object(object_intern, object); - if (!intern) { + if (!intern || !intern->items) { return Z_ARRVAL(ary); } diff --git a/metadata_collection.stub.php b/metadata_collection.stub.php index 32d5416e..902cba39 100644 --- a/metadata_collection.stub.php +++ b/metadata_collection.stub.php @@ -10,6 +10,9 @@ class Collection implements \Countable, \Iterator { + /** @implementation-alias RdKafka::__construct */ + private function __construct() {} + /** @tentative-return-type */ public function count(): int {} diff --git a/metadata_collection_arginfo.h b/metadata_collection_arginfo.h index 67b12734..4219f1e2 100644 --- a/metadata_collection_arginfo.h +++ b/metadata_collection_arginfo.h @@ -1,5 +1,8 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: a84f8bd542d46b72179ff6aa0d9d17bed530a2de */ + * Stub hash: 43c071a00a4c0beb6b5c1f8f685e29b746c2d3fb */ + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RdKafka_Metadata_Collection___construct, 0, 0, 0) +ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_RdKafka_Metadata_Collection_count, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -18,6 +21,7 @@ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_RdKafka_Metadata ZEND_END_ARG_INFO() +ZEND_METHOD(RdKafka, __construct); ZEND_METHOD(RdKafka_Metadata_Collection, count); ZEND_METHOD(RdKafka_Metadata_Collection, current); ZEND_METHOD(RdKafka_Metadata_Collection, key); @@ -27,6 +31,7 @@ ZEND_METHOD(RdKafka_Metadata_Collection, valid); static const zend_function_entry class_RdKafka_Metadata_Collection_methods[] = { + ZEND_MALIAS(RdKafka, __construct, __construct, arginfo_class_RdKafka_Metadata_Collection___construct, ZEND_ACC_PRIVATE) ZEND_ME(RdKafka_Metadata_Collection, count, arginfo_class_RdKafka_Metadata_Collection_count, ZEND_ACC_PUBLIC) ZEND_ME(RdKafka_Metadata_Collection, current, arginfo_class_RdKafka_Metadata_Collection_current, ZEND_ACC_PUBLIC) ZEND_ME(RdKafka_Metadata_Collection, key, arginfo_class_RdKafka_Metadata_Collection_key, ZEND_ACC_PUBLIC) diff --git a/metadata_collection_legacy_arginfo.h b/metadata_collection_legacy_arginfo.h index 81c1f674..16f47592 100644 --- a/metadata_collection_legacy_arginfo.h +++ b/metadata_collection_legacy_arginfo.h @@ -1,5 +1,8 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: a84f8bd542d46b72179ff6aa0d9d17bed530a2de */ + * Stub hash: 43c071a00a4c0beb6b5c1f8f685e29b746c2d3fb */ + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RdKafka_Metadata_Collection___construct, 0, 0, 0) +ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RdKafka_Metadata_Collection_count, 0, 0, 0) ZEND_END_ARG_INFO() @@ -15,6 +18,7 @@ ZEND_END_ARG_INFO() #define arginfo_class_RdKafka_Metadata_Collection_valid arginfo_class_RdKafka_Metadata_Collection_count +ZEND_METHOD(RdKafka, __construct); ZEND_METHOD(RdKafka_Metadata_Collection, count); ZEND_METHOD(RdKafka_Metadata_Collection, current); ZEND_METHOD(RdKafka_Metadata_Collection, key); @@ -24,6 +28,7 @@ ZEND_METHOD(RdKafka_Metadata_Collection, valid); static const zend_function_entry class_RdKafka_Metadata_Collection_methods[] = { + ZEND_MALIAS(RdKafka, __construct, __construct, arginfo_class_RdKafka_Metadata_Collection___construct, ZEND_ACC_PRIVATE) ZEND_ME(RdKafka_Metadata_Collection, count, arginfo_class_RdKafka_Metadata_Collection_count, ZEND_ACC_PUBLIC) ZEND_ME(RdKafka_Metadata_Collection, current, arginfo_class_RdKafka_Metadata_Collection_current, ZEND_ACC_PUBLIC) ZEND_ME(RdKafka_Metadata_Collection, key, arginfo_class_RdKafka_Metadata_Collection_key, ZEND_ACC_PUBLIC) diff --git a/metadata_legacy_arginfo.h b/metadata_legacy_arginfo.h index 104ff219..8d190dc0 100644 --- a/metadata_legacy_arginfo.h +++ b/metadata_legacy_arginfo.h @@ -1,5 +1,8 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 7bdf537cb18915955d6c3f1d4775dcc9fc43eb4a */ + * Stub hash: 6c980079f802be29ef2c30e235a6071f5c0d628c */ + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RdKafka_Metadata___construct, 0, 0, 0) +ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RdKafka_Metadata_getOrigBrokerId, 0, 0, 0) ZEND_END_ARG_INFO() @@ -11,6 +14,7 @@ ZEND_END_ARG_INFO() #define arginfo_class_RdKafka_Metadata_getTopics arginfo_class_RdKafka_Metadata_getOrigBrokerId +ZEND_METHOD(RdKafka, __construct); ZEND_METHOD(RdKafka_Metadata, getOrigBrokerId); ZEND_METHOD(RdKafka_Metadata, getOrigBrokerName); ZEND_METHOD(RdKafka_Metadata, getBrokers); @@ -18,6 +22,7 @@ ZEND_METHOD(RdKafka_Metadata, getTopics); static const zend_function_entry class_RdKafka_Metadata_methods[] = { + ZEND_MALIAS(RdKafka, __construct, __construct, arginfo_class_RdKafka_Metadata___construct, ZEND_ACC_PRIVATE) ZEND_ME(RdKafka_Metadata, getOrigBrokerId, arginfo_class_RdKafka_Metadata_getOrigBrokerId, ZEND_ACC_PUBLIC) ZEND_ME(RdKafka_Metadata, getOrigBrokerName, arginfo_class_RdKafka_Metadata_getOrigBrokerName, ZEND_ACC_PUBLIC) ZEND_ME(RdKafka_Metadata, getBrokers, arginfo_class_RdKafka_Metadata_getBrokers, ZEND_ACC_PUBLIC) diff --git a/metadata_partition.c b/metadata_partition.c index 3a1bf7a3..c8a6c7db 100644 --- a/metadata_partition.c +++ b/metadata_partition.c @@ -95,7 +95,7 @@ static HashTable *get_debug_info(Z_RDKAFKA_OBJ *object, int *is_temp) /* {{{ */ array_init(&ary); intern = rdkafka_get_debug_object(object_intern, object); - if (!intern) { + if (!intern || !intern->metadata_partition) { return Z_ARRVAL(ary); } diff --git a/metadata_partition.stub.php b/metadata_partition.stub.php index 9215e07c..f4a724ab 100644 --- a/metadata_partition.stub.php +++ b/metadata_partition.stub.php @@ -10,6 +10,9 @@ class Partition { + /** @implementation-alias RdKafka::__construct */ + private function __construct() {} + /** @tentative-return-type */ public function getId(): int {} diff --git a/metadata_partition_arginfo.h b/metadata_partition_arginfo.h index 4f2044bb..cae4d519 100644 --- a/metadata_partition_arginfo.h +++ b/metadata_partition_arginfo.h @@ -1,5 +1,8 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 4c02c5ac3a6240ab8cbc90451bdc54a3de2c2d2f */ + * Stub hash: ce824cf273ec8fec1fe3b6eaac015a51f3e9dc6b */ + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RdKafka_Metadata_Partition___construct, 0, 0, 0) +ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_RdKafka_Metadata_Partition_getId, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -14,6 +17,7 @@ ZEND_END_ARG_INFO() #define arginfo_class_RdKafka_Metadata_Partition_getIsrs arginfo_class_RdKafka_Metadata_Partition_getReplicas +ZEND_METHOD(RdKafka, __construct); ZEND_METHOD(RdKafka_Metadata_Partition, getId); ZEND_METHOD(RdKafka_Metadata_Partition, getErr); ZEND_METHOD(RdKafka_Metadata_Partition, getLeader); @@ -22,6 +26,7 @@ ZEND_METHOD(RdKafka_Metadata_Partition, getIsrs); static const zend_function_entry class_RdKafka_Metadata_Partition_methods[] = { + ZEND_MALIAS(RdKafka, __construct, __construct, arginfo_class_RdKafka_Metadata_Partition___construct, ZEND_ACC_PRIVATE) ZEND_ME(RdKafka_Metadata_Partition, getId, arginfo_class_RdKafka_Metadata_Partition_getId, ZEND_ACC_PUBLIC) ZEND_ME(RdKafka_Metadata_Partition, getErr, arginfo_class_RdKafka_Metadata_Partition_getErr, ZEND_ACC_PUBLIC) ZEND_ME(RdKafka_Metadata_Partition, getLeader, arginfo_class_RdKafka_Metadata_Partition_getLeader, ZEND_ACC_PUBLIC) diff --git a/metadata_partition_legacy_arginfo.h b/metadata_partition_legacy_arginfo.h index 1939ba07..13c2e716 100644 --- a/metadata_partition_legacy_arginfo.h +++ b/metadata_partition_legacy_arginfo.h @@ -1,5 +1,8 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 4c02c5ac3a6240ab8cbc90451bdc54a3de2c2d2f */ + * Stub hash: ce824cf273ec8fec1fe3b6eaac015a51f3e9dc6b */ + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RdKafka_Metadata_Partition___construct, 0, 0, 0) +ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RdKafka_Metadata_Partition_getId, 0, 0, 0) ZEND_END_ARG_INFO() @@ -13,6 +16,7 @@ ZEND_END_ARG_INFO() #define arginfo_class_RdKafka_Metadata_Partition_getIsrs arginfo_class_RdKafka_Metadata_Partition_getId +ZEND_METHOD(RdKafka, __construct); ZEND_METHOD(RdKafka_Metadata_Partition, getId); ZEND_METHOD(RdKafka_Metadata_Partition, getErr); ZEND_METHOD(RdKafka_Metadata_Partition, getLeader); @@ -21,6 +25,7 @@ ZEND_METHOD(RdKafka_Metadata_Partition, getIsrs); static const zend_function_entry class_RdKafka_Metadata_Partition_methods[] = { + ZEND_MALIAS(RdKafka, __construct, __construct, arginfo_class_RdKafka_Metadata_Partition___construct, ZEND_ACC_PRIVATE) ZEND_ME(RdKafka_Metadata_Partition, getId, arginfo_class_RdKafka_Metadata_Partition_getId, ZEND_ACC_PUBLIC) ZEND_ME(RdKafka_Metadata_Partition, getErr, arginfo_class_RdKafka_Metadata_Partition_getErr, ZEND_ACC_PUBLIC) ZEND_ME(RdKafka_Metadata_Partition, getLeader, arginfo_class_RdKafka_Metadata_Partition_getLeader, ZEND_ACC_PUBLIC) diff --git a/metadata_topic.c b/metadata_topic.c index 4bef7759..d2f9fff9 100644 --- a/metadata_topic.c +++ b/metadata_topic.c @@ -102,7 +102,7 @@ static HashTable *get_debug_info(Z_RDKAFKA_OBJ *object, int *is_temp) /* {{{ */ array_init(&ary); intern = rdkafka_get_debug_object(object_intern, object); - if (!intern) { + if (!intern || !intern->metadata_topic) { return Z_ARRVAL(ary); } diff --git a/metadata_topic.stub.php b/metadata_topic.stub.php index 73650159..5b12228a 100644 --- a/metadata_topic.stub.php +++ b/metadata_topic.stub.php @@ -10,6 +10,9 @@ class Topic { + /** @implementation-alias RdKafka::__construct */ + private function __construct() {} + /** @tentative-return-type */ public function getTopic(): string {} diff --git a/metadata_topic_arginfo.h b/metadata_topic_arginfo.h index 5ca7d671..73bf989c 100644 --- a/metadata_topic_arginfo.h +++ b/metadata_topic_arginfo.h @@ -1,5 +1,8 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 90ddb49b26a651772f9b71a1233435f2a502af6d */ + * Stub hash: 04fd71ae954bd0a09730d401c8160574e1045369 */ + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RdKafka_Metadata_Topic___construct, 0, 0, 0) +ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_RdKafka_Metadata_Topic_getTopic, 0, 0, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -11,12 +14,14 @@ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_RdKafka_Metadata_ ZEND_END_ARG_INFO() +ZEND_METHOD(RdKafka, __construct); ZEND_METHOD(RdKafka_Metadata_Topic, getTopic); ZEND_METHOD(RdKafka_Metadata_Topic, getErr); ZEND_METHOD(RdKafka_Metadata_Topic, getPartitions); static const zend_function_entry class_RdKafka_Metadata_Topic_methods[] = { + ZEND_MALIAS(RdKafka, __construct, __construct, arginfo_class_RdKafka_Metadata_Topic___construct, ZEND_ACC_PRIVATE) ZEND_ME(RdKafka_Metadata_Topic, getTopic, arginfo_class_RdKafka_Metadata_Topic_getTopic, ZEND_ACC_PUBLIC) ZEND_ME(RdKafka_Metadata_Topic, getErr, arginfo_class_RdKafka_Metadata_Topic_getErr, ZEND_ACC_PUBLIC) ZEND_ME(RdKafka_Metadata_Topic, getPartitions, arginfo_class_RdKafka_Metadata_Topic_getPartitions, ZEND_ACC_PUBLIC) diff --git a/metadata_topic_legacy_arginfo.h b/metadata_topic_legacy_arginfo.h index 6aa13153..8224ac4f 100644 --- a/metadata_topic_legacy_arginfo.h +++ b/metadata_topic_legacy_arginfo.h @@ -1,5 +1,8 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 90ddb49b26a651772f9b71a1233435f2a502af6d */ + * Stub hash: 04fd71ae954bd0a09730d401c8160574e1045369 */ + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RdKafka_Metadata_Topic___construct, 0, 0, 0) +ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RdKafka_Metadata_Topic_getTopic, 0, 0, 0) ZEND_END_ARG_INFO() @@ -9,12 +12,14 @@ ZEND_END_ARG_INFO() #define arginfo_class_RdKafka_Metadata_Topic_getPartitions arginfo_class_RdKafka_Metadata_Topic_getTopic +ZEND_METHOD(RdKafka, __construct); ZEND_METHOD(RdKafka_Metadata_Topic, getTopic); ZEND_METHOD(RdKafka_Metadata_Topic, getErr); ZEND_METHOD(RdKafka_Metadata_Topic, getPartitions); static const zend_function_entry class_RdKafka_Metadata_Topic_methods[] = { + ZEND_MALIAS(RdKafka, __construct, __construct, arginfo_class_RdKafka_Metadata_Topic___construct, ZEND_ACC_PRIVATE) ZEND_ME(RdKafka_Metadata_Topic, getTopic, arginfo_class_RdKafka_Metadata_Topic_getTopic, ZEND_ACC_PUBLIC) ZEND_ME(RdKafka_Metadata_Topic, getErr, arginfo_class_RdKafka_Metadata_Topic_getErr, ZEND_ACC_PUBLIC) ZEND_ME(RdKafka_Metadata_Topic, getPartitions, arginfo_class_RdKafka_Metadata_Topic_getPartitions, ZEND_ACC_PUBLIC) diff --git a/package.xml b/package.xml index 62dab9eb..368fcb8a 100644 --- a/package.xml +++ b/package.xml @@ -124,6 +124,11 @@ + + + + + @@ -140,7 +145,8 @@ - + + diff --git a/php_rdkafka_priv.h b/php_rdkafka_priv.h index aad32f91..695a2739 100644 --- a/php_rdkafka_priv.h +++ b/php_rdkafka_priv.h @@ -67,7 +67,7 @@ #define Z_RDKAFKA_PROP_OBJ(object) object -#define rdkafka_get_debug_object(type, object) get_object(object) +#define rdkafka_get_debug_object(type, object) php_kafka_from_obj(type, Z_OBJ_P(object)) #if PHP_MINOR_VERSION < 3 /* Allocates object type and zeros it, but not the properties. diff --git a/tests/metadata_001.phpt b/tests/metadata_001.phpt new file mode 100644 index 00000000..b081a8d5 --- /dev/null +++ b/tests/metadata_001.phpt @@ -0,0 +1,41 @@ +--TEST-- +Metadata 001 +--FILE-- +getMessage(), "\n"; +} + +// Metadata can be sub-classed and instantiated for the purpose of mocking +class M extends RdKafka\Metadata +{ + public function __construct() + { + } +} + +$m = new M(); +var_dump($m); + +// Metadata can be instantied via reflection +$m = (new ReflectionClass(RdKafka\Metadata::class))->newInstanceWithoutConstructor(); +var_dump($m); +try { + $m->getTopics(); +} catch(Exception $e) { + echo $e->getMessage(), "\n"; +} +?> +==DONE== +--EXPECTF-- +Call to private RdKafka\Metadata::__construct() from %rglobal scope|invalid context%r +object(M)#%d (0) { +} +object(RdKafka\Metadata)#%d (0) { +} +RdKafka\Metadata::__construct() has not been called +==DONE== diff --git a/tests/metadata_broker_001.phpt b/tests/metadata_broker_001.phpt new file mode 100644 index 00000000..c2a9ed19 --- /dev/null +++ b/tests/metadata_broker_001.phpt @@ -0,0 +1,41 @@ +--TEST-- +Metadata\Broker 001 +--FILE-- +getMessage(), "\n"; +} + +// Metadata\Broker can be sub-classed and instantiated for the purpose of mocking +class M extends RdKafka\Metadata\Broker +{ + public function __construct() + { + } +} + +$i = new M(); +var_dump($i); + +// Metadata\Broker can be instantied via reflection +$i = (new ReflectionClass(RdKafka\Metadata\Broker::class))->newInstanceWithoutConstructor(); +var_dump($i); +try { + $i->getId(); +} catch(Exception $e) { + echo $e->getMessage(), "\n"; +} +?> +==DONE== +--EXPECTF-- +Call to private RdKafka\Metadata\Broker::__construct() from %rglobal scope|invalid context%r +object(M)#%d (0) { +} +object(RdKafka\Metadata\Broker)#%d (0) { +} +RdKafka\Metadata\Broker::__construct() has not been called +==DONE== diff --git a/tests/metadata_collection_001.phpt b/tests/metadata_collection_001.phpt new file mode 100644 index 00000000..3de55107 --- /dev/null +++ b/tests/metadata_collection_001.phpt @@ -0,0 +1,48 @@ +--TEST-- +Metadata\Collection 001 +--FILE-- +getMessage(), "\n"; +} + +// Metadata\Collection can be sub-classed and instantiated for the purpose of mocking +class M extends RdKafka\Metadata\Collection +{ + public function __construct() + { + } +} + +$i = new M(); +var_dump($i); + +// Metadata\Collection can be instantied via reflection +$i = (new ReflectionClass(RdKafka\Metadata\Collection::class))->newInstanceWithoutConstructor(); +var_dump($i); +try { + $i->count(); +} catch(Exception $e) { + echo $e->getMessage(), "\n"; +} +try { + foreach ($i as $_) { + } +} catch(Exception $e) { + echo $e->getMessage(), "\n"; +} +?> +==DONE== +--EXPECTF-- +Call to private RdKafka\Metadata\Collection::__construct() from %rglobal scope|invalid context%r +object(M)#%d (0) { +} +object(RdKafka\Metadata\Collection)#%d (0) { +} +RdKafka\Metadata\Collection::__construct() has not been called +RdKafka\Metadata\Collection::__construct() has not been called +==DONE== diff --git a/tests/metadata_partition_001.phpt b/tests/metadata_partition_001.phpt new file mode 100644 index 00000000..4cda4fcf --- /dev/null +++ b/tests/metadata_partition_001.phpt @@ -0,0 +1,41 @@ +--TEST-- +Metadata\Partition 001 +--FILE-- +getMessage(), "\n"; +} + +// Metadata\Partition can be sub-classed and instantiated for the purpose of mocking +class M extends RdKafka\Metadata\Partition +{ + public function __construct() + { + } +} + +$i = new M(); +var_dump($i); + +// Metadata\Partition can be instantied via reflection +$i = (new ReflectionClass(RdKafka\Metadata\Partition::class))->newInstanceWithoutConstructor(); +var_dump($i); +try { + $i->getId(); +} catch(Exception $e) { + echo $e->getMessage(), "\n"; +} +?> +==DONE== +--EXPECTF-- +Call to private RdKafka\Metadata\Partition::__construct() from %rglobal scope|invalid context%r +object(M)#%d (0) { +} +object(RdKafka\Metadata\Partition)#%d (0) { +} +RdKafka\Metadata\Partition::__construct() has not been called +==DONE== diff --git a/tests/metadata_topic_001.phpt b/tests/metadata_topic_001.phpt new file mode 100644 index 00000000..179133a6 --- /dev/null +++ b/tests/metadata_topic_001.phpt @@ -0,0 +1,41 @@ +--TEST-- +Metadata\Topic 001 +--FILE-- +getMessage(), "\n"; +} + +// Metadata\Topic can be sub-classed and instantiated for the purpose of mocking +class M extends RdKafka\Metadata\Topic +{ + public function __construct() + { + } +} + +$i = new M(); +var_dump($i); + +// Metadata\Topic can be instantied via reflection +$i = (new ReflectionClass(RdKafka\Metadata\Topic::class))->newInstanceWithoutConstructor(); +var_dump($i); +try { + $i->getTopic(); +} catch(Exception $e) { + echo $e->getMessage(), "\n"; +} +?> +==DONE== +--EXPECTF-- +Call to private RdKafka\Metadata\Topic::__construct() from %rglobal scope|invalid context%r +object(M)#%d (0) { +} +object(RdKafka\Metadata\Topic)#%d (0) { +} +RdKafka\Metadata\Topic::__construct() has not been called +==DONE== diff --git a/tests/topic_partition.phpt b/tests/topic_partition_001.phpt similarity index 96% rename from tests/topic_partition.phpt rename to tests/topic_partition_001.phpt index 9e8b5507..f21bc6cb 100644 --- a/tests/topic_partition.phpt +++ b/tests/topic_partition_001.phpt @@ -1,5 +1,5 @@ --TEST-- -RdKafka\TopicPartition +RdKafka\TopicPartition 001 --SKIPIF-- +--FILE-- +newInstanceWithoutConstructor(); +var_dump($i); +try { + $i->getTopic(); +} catch(Exception $e) { + echo $e->getMessage(), "\n"; +} +?> +==DONE== +--EXPECTF-- +object(M)#%d (0) { +} +object(RdKafka\TopicPartition)#%d (0) { +} +RdKafka\TopicPartition::__construct() has not been called +==DONE== diff --git a/topic_partition.c b/topic_partition.c index 532a7167..268364e2 100644 --- a/topic_partition.c +++ b/topic_partition.c @@ -100,7 +100,7 @@ static HashTable *get_debug_info(Z_RDKAFKA_OBJ *object, int *is_temp) /* {{{ */ intern = rdkafka_get_debug_object(object_intern, object); - if (!intern) { + if (!intern || !intern->topic) { return Z_ARRVAL(ary); }