瀏覽代碼

feat increase resource handle

viest 7 年之前
父節點
當前提交
25d62d7d24
共有 5 個文件被更改,包括 48 次插入4 次删除
  1. 36 2
      kernel/excel.c
  2. 2 1
      kernel/excel.h
  3. 7 0
      kernel/excel.loT
  4. 1 1
      php_vtiful.h
  5. 2 0
      vtiful.c

+ 36 - 2
kernel/excel.c

@@ -66,8 +66,9 @@ PHP_METHOD(vtiful_excel, __construct)
  */
 PHP_METHOD(vtiful_excel, fileName)
 {
-    zval rv, tmp_file_name, *config, *tmp_path, file_path;
+    zval rv, tmp_file_name, file_path, handle, *config, *tmp_path;
     zend_string *file_name, *key;
+    excel_resource_t *res;
 
     ZEND_PARSE_PARAMETERS_START(1, 1)
             Z_PARAM_STR(file_name)
@@ -78,6 +79,7 @@ PHP_METHOD(vtiful_excel, fileName)
     key      = zend_string_init(V_EXCEL_PAT, sizeof(V_EXCEL_PAT)-1, 0);
     config   = zend_read_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_COF), 0, &rv TSRMLS_DC);
     tmp_path = zend_hash_find(Z_ARRVAL_P(config), key);
+
     zend_string_release(key);
 
     if(!tmp_path && Z_TYPE_P(tmp_path) != IS_STRING)
@@ -88,7 +90,16 @@ PHP_METHOD(vtiful_excel, fileName)
     ZVAL_STR(&tmp_file_name, file_name);
     concat_function(&file_path, tmp_path, &tmp_file_name);
 
+    res = malloc(sizeof(excel_resource_t));
+    res->workbook  = workbook_new(ZSTR_VAL(zval_get_string(&file_path)));
+    res->worksheet = workbook_add_worksheet(res->workbook, NULL);
+
+    ZVAL_RES(&handle, zend_register_resource(res, le_vtiful));
+
     zend_update_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_FIL), &file_path);
+    zend_update_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_HANDLE), &handle);
+
+    zval_ptr_dtor(&file_path);
     zval_ptr_dtor(&file_path);
 }
 /* }}} */
@@ -168,12 +179,34 @@ PHP_METHOD(vtiful_excel, output)
 }
 /* }}} */
 
+/* {{{ \Vtiful\Kernel\Excel::getHandle()
+ */
+PHP_METHOD(vtiful_excel, getHandle)
+{
+    zval rv;
+    zval *file_name;
+    excel_resource_t *res;
+
+    file_name = zend_read_property(vtiful_excel_ce, getThis(), ZEND_STRL(V_EXCEL_FIL), 0, &rv TSRMLS_DC);
+
+    res = malloc(sizeof(excel_resource_t));
+
+    res->workbook  = workbook_new(ZSTR_VAL(zval_get_string(file_name)));
+    res->worksheet = workbook_add_worksheet(res->workbook, NULL);
+
+    zval_ptr_dtor(file_name);
+
+    RETURN_RES(zend_register_resource(res, le_vtiful));
+}
+/* }}} */
+
 zend_function_entry excel_methods[] = {
         PHP_ME(vtiful_excel, __construct, excel_construct_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
         PHP_ME(vtiful_excel, fileName,    excel_file_name_arginfo, ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_excel, header,      excel_header_arginfo,    ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_excel, data,        excel_data_arginfo,      ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_excel, output,      NULL,                    ZEND_ACC_PUBLIC)
+        PHP_ME(vtiful_excel, getHandle,   NULL,                    ZEND_ACC_PUBLIC)
         PHP_FE_END
 };
 
@@ -186,8 +219,9 @@ VTIFUL_STARTUP_FUNCTION(excel) {
 
     zend_declare_property_null(vtiful_excel_ce, ZEND_STRL(V_EXCEL_COF), ZEND_ACC_PRIVATE);
     zend_declare_property_null(vtiful_excel_ce, ZEND_STRL(V_EXCEL_FIL), ZEND_ACC_PRIVATE);
-    zend_declare_property_null(vtiful_excel_ce, ZEND_STRL(V_EXCEL_HEADER), ZEND_ACC_PRIVATE);
     zend_declare_property_null(vtiful_excel_ce, ZEND_STRL(V_EXCEL_DATA), ZEND_ACC_PRIVATE);
+    zend_declare_property_null(vtiful_excel_ce, ZEND_STRL(V_EXCEL_HEADER), ZEND_ACC_PRIVATE);
+    zend_declare_property_null(vtiful_excel_ce, ZEND_STRL(V_EXCEL_HANDLE), ZEND_ACC_PRIVATE);
 
     return SUCCESS;
 }

+ 2 - 1
kernel/excel.h

@@ -1,9 +1,10 @@
 #ifndef VTIFUL_EXCEL_H
 #define VTIFUL_EXCEL_H
 
+#define V_EXCEL_HEADER "header"
+#define V_EXCEL_HANDLE "handle"
 #define V_EXCEL_FIL "fileName"
 #define V_EXCEL_COF "config"
-#define V_EXCEL_HEADER "header"
 #define V_EXCEL_DATA "data"
 #define V_EXCEL_PAT "path"
 

+ 7 - 0
kernel/excel.loT

@@ -0,0 +1,7 @@
+# kernel/excel.lo - a libtool object file
+# Generated by ltmain.sh - GNU libtool 1.5.26 (1.1220.2.492 2008/01/30 06:40:56)
+#
+# Please DO NOT delete this file!
+# It is necessary for linking the library.
+
+# Name of the PIC object.

+ 1 - 1
php_vtiful.h

@@ -30,7 +30,7 @@ extern zend_module_entry vtiful_module_entry;
 #include "TSRM.h"
 #endif
 
-static int le_vtiful;
+extern int le_vtiful;
 
 #define VTIFUL_STARTUP_MODULE(module) ZEND_MODULE_STARTUP_N(vtiful_##module)(INIT_FUNC_ARGS_PASSTHRU)
 #define VTIFUL_STARTUP_FUNCTION(module) ZEND_MINIT_FUNCTION(vtiful_##module)

+ 2 - 0
vtiful.c

@@ -22,6 +22,8 @@
 #include "kernel/excel.h"
 #include "kernel/exception.h"
 
+int le_vtiful;
+
 PHP_MINIT_FUNCTION(vtiful)
 {
 	/* If you have INI entries, uncomment these lines