Skip to content

Commit 7c3d4f9

Browse files
committed
backport changes from php7 branch
1 parent 25d267d commit 7c3d4f9

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

config.m4

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ if test "$PHP_EXCEL" != "no"; then
8686
-L$EXCEL_LIBDIR
8787
])
8888

89+
PHP_CHECK_LIBRARY(xl,xlBookSetKeyA,
90+
[
91+
AC_DEFINE(HAVE_LIBXL_SETKEY,1,[ ])
92+
],[],[])
93+
8994
if test `grep -c FILLPATTERN_HORSTRIPE $EXCEL_INCDIR/enum.h` -eq 1; then
9095
AC_DEFINE(HAVE_LIBXL_243_PLUS,1,[ ])
9196
fi

config.w32

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ if (PHP_EXCEL != "no") {
55
EXTENSION("excel", "excel.c");
66
AC_DEFINE('HAVE_EXCELLIB', 1, 'Have LibXL library');
77
AC_DEFINE('HAVE_LIBXL_243_PLUS', 1, 'Have LibXL version 2.4.3 or later');
8+
AC_DEFINE("HAVE_LIBXL_SETKEY", 1, "non-source libxl build");
89
AC_DEFINE("EXCEL_WITH_LIBXML", 1, "libxml support");
910
} else {
1011
WARNING("excel not enabled; libraries and headers not found");

excel.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ ZEND_DECLARE_MODULE_GLOBALS(excel)
7979
static PHP_GINIT_FUNCTION(excel);
8080

8181
PHP_INI_BEGIN()
82+
#if defined(HAVE_LIBXL_SETKEY)
8283
STD_PHP_INI_ENTRY("excel.license_name", NULL, PHP_INI_ALL, OnUpdateString, ini_license_name, zend_excel_globals, excel_globals)
8384
STD_PHP_INI_ENTRY("excel.license_key", NULL, PHP_INI_ALL, OnUpdateString, ini_license_key, zend_excel_globals, excel_globals)
85+
#endif
8486
STD_PHP_INI_ENTRY("excel.skip_empty", "0", PHP_INI_ALL, OnUpdateLong, ini_skip_empty, zend_excel_globals, excel_globals)
8587
PHP_INI_END()
8688

@@ -387,6 +389,19 @@ static wchar_t * _php_excel_to_wide(const char *string, size_t len, size_t *out_
387389
#define EXCEL_METHOD(class_name, function_name) \
388390
PHP_METHOD(Excel ## class_name, function_name)
389391

392+
393+
/* {{{ proto bool ExcelBook::requiresKey()
394+
true if license key is required. */
395+
EXCEL_METHOD(Book, requiresKey)
396+
{
397+
#if defined(HAVE_LIBXL_SETKEY)
398+
RETURN_BOOL(1);
399+
#else
400+
RETURN_BOOL(0);
401+
#endif
402+
}
403+
/* }}} */
404+
390405
/* {{{ proto bool ExcelBook::load(string data)
391406
Load Excel data string. */
392407
EXCEL_METHOD(Book, load)
@@ -1240,6 +1255,7 @@ EXCEL_METHOD(Book, __construct)
12401255
RETURN_FALSE;
12411256
}
12421257
#endif
1258+
#if defined(HAVE_LIBXL_SETKEY)
12431259
if (!name_len) {
12441260
if (INI_STR("excel.license_name") && INI_STR("excel.license_key")) {
12451261
name = INI_STR("excel.license_name");
@@ -1252,6 +1268,7 @@ EXCEL_METHOD(Book, __construct)
12521268
#endif
12531269
}
12541270
}
1271+
#endif
12551272

12561273
BOOK_FROM_OBJECT(book, object);
12571274
#ifdef LIBXL_VERSION
@@ -1263,6 +1280,9 @@ EXCEL_METHOD(Book, __construct)
12631280
} else {
12641281
RETURN_FALSE;
12651282
}
1283+
#if !defined(HAVE_LIBXL_SETKEY)
1284+
return;
1285+
#endif
12661286
if (!name_len && !key_len) {
12671287
return;
12681288
}

tests/088.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ bool(true)
3131
bool(false)
3232
bool(false)
3333
bool(false)
34-
string(5) "=3+4"
35-
string(1) ""
36-
string(2) "3"
34+
string(4) "=3+4"
35+
string(0) ""
36+
string(1) "3"
3737
OK

0 commit comments

Comments
 (0)