Skip to content

Commit b3f9606

Browse files
committed
Fix(PHP81): api
1 parent fdcd294 commit b3f9606

File tree

4 files changed

+66
-29
lines changed

4 files changed

+66
-29
lines changed

include/xlswriter.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,21 @@ typedef struct _vtiful_validation_object {
207207
#define PROP_OBJ(zv) Z_OBJ_P(zv)
208208
#endif
209209

210+
#if PHP_VERSION_ID < 80000
211+
#define Z_PARAM_STRING_OR_NULL(dest, dest_len) \
212+
Z_PARAM_STRING_EX(dest, dest_len, 1, 0)
213+
#define Z_PARAM_STR_OR_NULL(dest) \
214+
Z_PARAM_STR_EX(dest, 1, 0)
215+
#define Z_PARAM_RESOURCE_OR_NULL(dest) \
216+
Z_PARAM_RESOURCE_EX(dest, 1, 0)
217+
#define Z_PARAM_DOUBLE_OR_NULL(dest, is_null) \
218+
Z_PARAM_DOUBLE_EX(dest, is_null, 1, 0)
219+
#define Z_PARAM_LONG_OR_NULL(dest, is_null) \
220+
Z_PARAM_LONG_EX(dest, is_null, 1, 0)
221+
#define Z_PARAM_ARRAY_OR_NULL(dest) \
222+
Z_PARAM_ARRAY_EX(dest, 1, 0)
223+
#endif
224+
210225
static inline xls_object *php_vtiful_xls_fetch_object(zend_object *obj) {
211226
if (obj == NULL) {
212227
return NULL;

kernel/csv.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,22 @@ unsigned int xlsx_to_csv(
9494
zend_call_function(fci, fci_cache);
9595

9696
if (Z_TYPE(retval) == IS_ARRAY) {
97+
#if PHP_VERSION_ID >= 80100
98+
ret = php_fputcsv(_stream_t, &retval, delimiter, enclosure, escape_char, NULL);
99+
#else
97100
ret = php_fputcsv(_stream_t, &retval, delimiter, enclosure, escape_char);
101+
#endif
98102
}
99103

100104
zval_ptr_dtor(&retval);
101105
goto CLEAN_UP_SCENE;
102106
}
103107

108+
#if PHP_VERSION_ID >= 80100
109+
ret = php_fputcsv(_stream_t, &_zv_tmp_row, delimiter, enclosure, escape_char, NULL);
110+
#else
104111
ret = php_fputcsv(_stream_t, &_zv_tmp_row, delimiter, enclosure, escape_char);
112+
#endif
105113

106114
CLEAN_UP_SCENE:
107115

kernel/excel.c

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ PHP_METHOD(vtiful_xls, fileName)
327327
ZEND_PARSE_PARAMETERS_START(1, 2)
328328
Z_PARAM_STR(zs_file_name)
329329
Z_PARAM_OPTIONAL
330-
Z_PARAM_STR(zs_sheet_name)
330+
Z_PARAM_STR_OR_NULL(zs_sheet_name)
331331
ZEND_PARSE_PARAMETERS_END();
332332

333333
ZVAL_COPY(return_value, getThis());
@@ -367,7 +367,7 @@ PHP_METHOD(vtiful_xls, addSheet)
367367

368368
ZEND_PARSE_PARAMETERS_START(0, 1)
369369
Z_PARAM_OPTIONAL
370-
Z_PARAM_STR(zs_sheet_name)
370+
Z_PARAM_STR_OR_NULL(zs_sheet_name)
371371
ZEND_PARSE_PARAMETERS_END();
372372

373373
ZVAL_COPY(return_value, getThis());
@@ -458,7 +458,7 @@ PHP_METHOD(vtiful_xls, constMemory)
458458
ZEND_PARSE_PARAMETERS_START(1, 2)
459459
Z_PARAM_STR(zs_file_name)
460460
Z_PARAM_OPTIONAL
461-
Z_PARAM_STR(zs_sheet_name)
461+
Z_PARAM_STR_OR_NULL(zs_sheet_name)
462462
ZEND_PARSE_PARAMETERS_END();
463463

464464
ZVAL_COPY(return_value, getThis());
@@ -502,7 +502,7 @@ PHP_METHOD(vtiful_xls, header)
502502
ZEND_PARSE_PARAMETERS_START(1, 2)
503503
Z_PARAM_ARRAY(header)
504504
Z_PARAM_OPTIONAL
505-
Z_PARAM_RESOURCE(zv_format_handle)
505+
Z_PARAM_RESOURCE_OR_NULL(zv_format_handle)
506506
ZEND_PARSE_PARAMETERS_END();
507507

508508
ZVAL_COPY(return_value, getThis());
@@ -600,8 +600,8 @@ PHP_METHOD(vtiful_xls, insertText)
600600
Z_PARAM_LONG(column)
601601
Z_PARAM_ZVAL(data)
602602
Z_PARAM_OPTIONAL
603-
Z_PARAM_STR(format)
604-
Z_PARAM_RESOURCE(format_handle)
603+
Z_PARAM_STR_OR_NULL(format)
604+
Z_PARAM_RESOURCE_OR_NULL(format_handle)
605605
ZEND_PARSE_PARAMETERS_END();
606606

607607
ZVAL_COPY(return_value, getThis());
@@ -633,8 +633,8 @@ PHP_METHOD(vtiful_xls, insertDate)
633633
Z_PARAM_LONG(column)
634634
Z_PARAM_ZVAL(data)
635635
Z_PARAM_OPTIONAL
636-
Z_PARAM_STR(format)
637-
Z_PARAM_RESOURCE(format_handle)
636+
Z_PARAM_STR_OR_NULL(format)
637+
Z_PARAM_RESOURCE_OR_NULL(format_handle)
638638
ZEND_PARSE_PARAMETERS_END();
639639

640640
ZVAL_COPY(return_value, getThis());
@@ -707,9 +707,9 @@ PHP_METHOD(vtiful_xls, insertUrl)
707707
Z_PARAM_LONG(column)
708708
Z_PARAM_STR(url)
709709
Z_PARAM_OPTIONAL
710-
Z_PARAM_STR(text)
711-
Z_PARAM_STR(tool_tip)
712-
Z_PARAM_RESOURCE(format_handle)
710+
Z_PARAM_STR_OR_NULL(text)
711+
Z_PARAM_STR_OR_NULL(tool_tip)
712+
Z_PARAM_RESOURCE_OR_NULL(format_handle)
713713
ZEND_PARSE_PARAMETERS_END();
714714

715715
ZVAL_COPY(return_value, getThis());
@@ -739,8 +739,8 @@ PHP_METHOD(vtiful_xls, insertImage)
739739
Z_PARAM_LONG(column)
740740
Z_PARAM_ZVAL(image)
741741
Z_PARAM_OPTIONAL
742-
Z_PARAM_DOUBLE(width)
743-
Z_PARAM_DOUBLE(height)
742+
Z_PARAM_DOUBLE_OR_NULL(width, _dummy)
743+
Z_PARAM_DOUBLE_OR_NULL(height, _dummy)
744744
ZEND_PARSE_PARAMETERS_END();
745745

746746
ZVAL_COPY(return_value, getThis());
@@ -768,7 +768,7 @@ PHP_METHOD(vtiful_xls, insertFormula)
768768
Z_PARAM_LONG(column)
769769
Z_PARAM_STR(formula)
770770
Z_PARAM_OPTIONAL
771-
Z_PARAM_RESOURCE(format_handle)
771+
Z_PARAM_RESOURCE_OR_NULL(format_handle)
772772
ZEND_PARSE_PARAMETERS_END();
773773

774774
ZVAL_COPY(return_value, getThis());
@@ -857,7 +857,7 @@ PHP_METHOD(vtiful_xls, mergeCells)
857857
Z_PARAM_STR(range)
858858
Z_PARAM_ZVAL(data)
859859
Z_PARAM_OPTIONAL
860-
Z_PARAM_RESOURCE(format_handle)
860+
Z_PARAM_RESOURCE_OR_NULL(format_handle)
861861
ZEND_PARSE_PARAMETERS_END();
862862

863863
ZVAL_COPY(return_value, getThis());
@@ -890,7 +890,7 @@ PHP_METHOD(vtiful_xls, setColumn)
890890
Z_PARAM_STR(range)
891891
Z_PARAM_DOUBLE(width)
892892
Z_PARAM_OPTIONAL
893-
Z_PARAM_RESOURCE(format_handle)
893+
Z_PARAM_RESOURCE_OR_NULL(format_handle)
894894
ZEND_PARSE_PARAMETERS_END();
895895

896896
ZVAL_COPY(return_value, getThis());
@@ -923,7 +923,7 @@ PHP_METHOD(vtiful_xls, setRow)
923923
Z_PARAM_STR(range)
924924
Z_PARAM_DOUBLE(height)
925925
Z_PARAM_OPTIONAL
926-
Z_PARAM_RESOURCE(format_handle)
926+
Z_PARAM_RESOURCE_OR_NULL(format_handle)
927927
ZEND_PARSE_PARAMETERS_END();
928928

929929
ZVAL_COPY(return_value, getThis());
@@ -1045,7 +1045,7 @@ PHP_METHOD(vtiful_xls, timestampFromDateDouble)
10451045
double date = 0;
10461046

10471047
ZEND_PARSE_PARAMETERS_START(1, 1)
1048-
Z_PARAM_DOUBLE(date)
1048+
Z_PARAM_DOUBLE_OR_NULL(date, _dummy)
10491049
ZEND_PARSE_PARAMETERS_END();
10501050

10511051
if (date <= 0) {
@@ -1108,7 +1108,7 @@ PHP_METHOD(vtiful_xls, protection)
11081108

11091109
ZEND_PARSE_PARAMETERS_START(0, 1)
11101110
Z_PARAM_OPTIONAL
1111-
Z_PARAM_STR(password)
1111+
Z_PARAM_STR_OR_NULL(password)
11121112
ZEND_PARSE_PARAMETERS_END();
11131113

11141114
ZVAL_COPY(return_value, getThis());
@@ -1241,8 +1241,8 @@ PHP_METHOD(vtiful_xls, openSheet)
12411241

12421242
ZEND_PARSE_PARAMETERS_START(0, 2)
12431243
Z_PARAM_OPTIONAL
1244-
Z_PARAM_STR(zs_sheet_name)
1245-
Z_PARAM_LONG(zl_flag)
1244+
Z_PARAM_STR_OR_NULL(zs_sheet_name)
1245+
Z_PARAM_LONG_OR_NULL(zl_flag, _dummy)
12461246
ZEND_PARSE_PARAMETERS_END();
12471247

12481248
ZVAL_COPY(return_value, getThis());
@@ -1352,9 +1352,9 @@ PHP_METHOD(vtiful_xls, putCSV)
13521352
ZEND_PARSE_PARAMETERS_START(1, 4)
13531353
Z_PARAM_RESOURCE(fp)
13541354
Z_PARAM_OPTIONAL
1355-
Z_PARAM_STRING(delimiter_str, delimiter_str_len)
1356-
Z_PARAM_STRING(enclosure_str, enclosure_str_len)
1357-
Z_PARAM_STRING(escape_str,escape_str_len)
1355+
Z_PARAM_STRING_OR_NULL(delimiter_str, delimiter_str_len)
1356+
Z_PARAM_STRING_OR_NULL(enclosure_str, enclosure_str_len)
1357+
Z_PARAM_STRING_OR_NULL(escape_str,escape_str_len)
13581358
ZEND_PARSE_PARAMETERS_END();
13591359

13601360
xls_object *obj = Z_XLS_P(getThis());
@@ -1390,9 +1390,9 @@ PHP_METHOD(vtiful_xls, putCSVCallback)
13901390
Z_PARAM_FUNC(fci, fci_cache)
13911391
Z_PARAM_RESOURCE(fp)
13921392
Z_PARAM_OPTIONAL
1393-
Z_PARAM_STRING(delimiter_str, delimiter_str_len)
1394-
Z_PARAM_STRING(enclosure_str, enclosure_str_len)
1395-
Z_PARAM_STRING(escape_str,escape_str_len)
1393+
Z_PARAM_STRING_OR_NULL(delimiter_str, delimiter_str_len)
1394+
Z_PARAM_STRING_OR_NULL(enclosure_str, enclosure_str_len)
1395+
Z_PARAM_STRING_OR_NULL(escape_str,escape_str_len)
13961396
ZEND_PARSE_PARAMETERS_END();
13971397

13981398
xls_object *obj = Z_XLS_P(getThis());
@@ -1444,7 +1444,7 @@ PHP_METHOD(vtiful_xls, nextRow)
14441444

14451445
ZEND_PARSE_PARAMETERS_START(0, 1)
14461446
Z_PARAM_OPTIONAL
1447-
Z_PARAM_ARRAY(zv_type_t)
1447+
Z_PARAM_ARRAY_OR_NULL(zv_type_t)
14481448
ZEND_PARSE_PARAMETERS_END();
14491449

14501450
xls_object *obj = Z_XLS_P(getThis());
@@ -1472,7 +1472,7 @@ PHP_METHOD(vtiful_xls, nextCellCallback)
14721472
ZEND_PARSE_PARAMETERS_START(1, 2)
14731473
Z_PARAM_FUNC(fci, fci_cache)
14741474
Z_PARAM_OPTIONAL
1475-
Z_PARAM_STR(zs_sheet_name)
1475+
Z_PARAM_STR_OR_NULL(zs_sheet_name)
14761476
ZEND_PARSE_PARAMETERS_END();
14771477

14781478
xls_object *obj = Z_XLS_P(getThis());

kernel/help.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,14 @@ zend_long date_double_to_timestamp(double value) {
6464
/* {{{ */
6565
unsigned int directory_exists(const char *path) {
6666
zval dir_exists;
67+
68+
#if PHP_VERSION_ID >= 80100
69+
zend_string *zs_path = zend_string_init(path, strlen(path), 0);
70+
php_stat(zs_path, FS_IS_DIR, &dir_exists);
71+
zend_string_release(zs_path);
72+
#else
6773
php_stat(path, strlen(path), FS_IS_DIR, &dir_exists);
74+
#endif
6875

6976
if (Z_TYPE(dir_exists) == IS_FALSE) {
7077
zval_ptr_dtor(&dir_exists);
@@ -79,7 +86,14 @@ unsigned int directory_exists(const char *path) {
7986
/* {{{ */
8087
unsigned int file_exists(const char *path) {
8188
zval file_exists;
89+
90+
#if PHP_VERSION_ID >= 80100
91+
zend_string *zs_path = zend_string_init(path, strlen(path), 0);
92+
php_stat(zs_path, FS_IS_FILE, &file_exists);
93+
zend_string_release(zs_path);
94+
#else
8295
php_stat(path, strlen(path), FS_IS_FILE, &file_exists);
96+
#endif
8397

8498
if (Z_TYPE(file_exists) == IS_FALSE) {
8599
zval_ptr_dtor(&file_exists);

0 commit comments

Comments
 (0)