Skip to content

Commit d343e37

Browse files
authored
add err2name (#3)
1 parent e6d0c2e commit d343e37

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

functions.c

+20
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,26 @@ ZEND_FUNCTION(kafka_get_err_descs)
5656
}
5757
/* }}} */
5858

59+
/* {{{ proto string kafka_err2name(int $err)
60+
* Returns a human readable representation of a kafka error.
61+
*/
62+
ZEND_FUNCTION(kafka_err2name)
63+
{
64+
zend_long errorCode;
65+
const char *errname;
66+
67+
ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1)
68+
Z_PARAM_LONG(errorCode)
69+
ZEND_PARSE_PARAMETERS_END();
70+
71+
errname = rd_kafka_err2name(errorCode);
72+
73+
if (errname) {
74+
RETURN_STRING(errname);
75+
}
76+
}
77+
/* }}} */
78+
5979
/* {{{ proto string kafka_err2str(int $err)
6080
* Returns a human readable representation of a kafka error.
6181
*/

functions.stub.php

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ function kafka_err2str(int $errorCode): string {}
99
function kafka_thread_cnt(): int {}
1010

1111
function kafka_offset_tail(int $offset): int {}
12+
13+
function kafka_err2name(int $errorCode): string {}

functions_arginfo.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: e9788b5cc0cda9d51b182a72d08b4e699b7b5962 */
2+
* Stub hash: 365fed498b521d06e6f73aab3437072b3c24d1a3 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_kafka_get_err_descs, 0, 0, IS_ARRAY, 0)
55
ZEND_END_ARG_INFO()
@@ -15,17 +15,21 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_kafka_offset_tail, 0, 1, IS_LONG
1515
ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0)
1616
ZEND_END_ARG_INFO()
1717

18+
#define arginfo_kafka_err2name arginfo_kafka_err2str
19+
1820

1921
ZEND_FUNCTION(kafka_get_err_descs);
2022
ZEND_FUNCTION(kafka_err2str);
2123
ZEND_FUNCTION(kafka_thread_cnt);
2224
ZEND_FUNCTION(kafka_offset_tail);
25+
ZEND_FUNCTION(kafka_err2name);
2326

2427

2528
static const zend_function_entry ext_functions[] = {
2629
ZEND_FE(kafka_get_err_descs, arginfo_kafka_get_err_descs)
2730
ZEND_FE(kafka_err2str, arginfo_kafka_err2str)
2831
ZEND_FE(kafka_thread_cnt, arginfo_kafka_thread_cnt)
2932
ZEND_FE(kafka_offset_tail, arginfo_kafka_offset_tail)
33+
ZEND_FE(kafka_err2name, arginfo_kafka_err2name)
3034
ZEND_FE_END
3135
};

tests/functions.phpt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
constants
3+
--FILE--
4+
<?php
5+
var_dump(kafka_err2str(RD_KAFKA_RESP_ERR__UNKNOWN_PARTITION));
6+
var_dump(kafka_err2name(RD_KAFKA_RESP_ERR__UNKNOWN_PARTITION));
7+
--EXPECT--
8+
string(24) "Local: Unknown partition"
9+
string(18) "_UNKNOWN_PARTITION"

0 commit comments

Comments
 (0)