Permalink
Browse files

Added INI settings to set the License name and key globally

  • Loading branch information...
1 parent 19d5e36 commit 79dca6a918696cf375a92b7b3cd5bcf7057ed14c Edward Rudd committed Dec 1, 2010
Showing with 39 additions and 3 deletions.
  1. +33 −3 excel.c
  2. +6 −0 php_excel.h
View
36 excel.c
@@ -60,6 +60,15 @@ static long xlFormatBorderColor(FormatHandle f)
ZEND_GET_MODULE(excel)
#endif
+ZEND_DECLARE_MODULE_GLOBALS(excel)
+
+static PHP_GINIT_FUNCTION(excel);
+
+PHP_INI_BEGIN()
+ STD_PHP_INI_ENTRY("excel.license_name", NULL, PHP_INI_ALL, OnUpdateString, ini_license_name, zend_excel_globals, excel_globals)
+ STD_PHP_INI_ENTRY("excel.license_key", NULL, PHP_INI_ALL, OnUpdateString, ini_license_key, zend_excel_globals, excel_globals)
+PHP_INI_END()
+
/* {{{ OO init/structure stuff */
#define REGISTER_EXCEL_CLASS(name, c_name, clone) \
{ \
@@ -1027,7 +1036,7 @@ EXCEL_METHOD(Book, setLocale)
}
/* }}} */
-/* {{{ proto ExcelBook ExcelBook::__construct(string license_name, string license_key [, bool excel_2007 = false])
+/* {{{ proto ExcelBook ExcelBook::__construct([string license_name, string license_key [, bool excel_2007 = false]])
Book Contructor. */
EXCEL_METHOD(Book, __construct)
{
@@ -1049,7 +1058,14 @@ EXCEL_METHOD(Book, __construct)
}
#endif
if (!name) {
- return;
+ if (excel_globals.ini_license_name && excel_globals.ini_license_key) {
+ name = excel_globals.ini_license_name;
+ name_len = strlen(excel_globals.ini_license_name);
+ key = excel_globals.ini_license_key;
+ key_len = strlen(excel_globals.ini_license_key);
+ } else {
+ return;
+ }
}
BOOK_FROM_OBJECT(book, object);
@@ -4180,6 +4196,8 @@ zend_function_entry excel_funcs_format[] = {
*/
PHP_MINIT_FUNCTION(excel)
{
+ REGISTER_INI_ENTRIES();
+
REGISTER_EXCEL_CLASS(Book, book, NULL);
REGISTER_EXCEL_CLASS(Sheet, sheet, NULL);
REGISTER_EXCEL_CLASS(Format, format, excel_format_object_clone);
@@ -4425,6 +4443,14 @@ PHP_MINFO_FUNCTION(excel)
}
/* }}} */
+/* {{{ PHP_GINIT_FUNCTION
+ */
+static PHP_GINIT_FUNCTION(excel)
+{
+ memset(excel_globals, 0, sizeof(*excel_globals));
+}
+/* }}} */
+
/* {{{ excel_functions[]
*/
zend_function_entry excel_functions[] = {
@@ -4444,7 +4470,11 @@ zend_module_entry excel_module_entry = {
NULL,
PHP_MINFO(excel),
PHP_EXCEL_VERSION,
- STANDARD_MODULE_PROPERTIES
+ PHP_MODULE_GLOBALS(excel),
+ PHP_GINIT(excel),
+ NULL,
+ NULL,
+ STANDARD_MODULE_PROPERTIES_EX
};
/* }}} */
View
@@ -22,6 +22,12 @@
extern zend_module_entry excel_module_entry;
#define phpext_excel_ptr &excel_module_entry
+ZEND_BEGIN_MODULE_GLOBALS(excel)
+ char *ini_license_name;
+ char *ini_license_key;
+ZEND_END_MODULE_GLOBALS(excel)
+
+
#ifdef PHP_WIN32
#define PHP_EXCEL_API __declspec(dllexport)
#else

1 comment on commit 79dca6a

gibson commented on 79dca6a Jul 13, 2012

but its not working, i add to ini file 2 lines with license
license_name=""
license_key=""

and when i create class ExcelBook without params apllication crashed

Please sign in to comment.