Browse Source

STYLE(code)

viest 7 years ago
parent
commit
bc76026802
3 changed files with 13 additions and 14 deletions
  1. 7 9
      kernel/excel.c
  2. 6 0
      kernel/excel.h
  3. 0 5
      kernel/exception.c

+ 7 - 9
kernel/excel.c

@@ -87,7 +87,7 @@ PHP_METHOD(vtiful_excel, __construct)
             Z_PARAM_ARRAY(config)
     ZEND_PARSE_PARAMETERS_END();
 
-    if((c_path = zend_hash_str_find(Z_ARRVAL_P(config), V_EXCEL_PAT, sizeof(V_EXCEL_PAT)-1)) == NULL)
+    if((c_path = zend_hash_str_find(Z_ARRVAL_P(config), ZEND_STRL(V_EXCEL_PAT))) == NULL)
     {
         zend_throw_exception(vtiful_exception_ce, "Lack of 'path' configuration", 110);
         return;
@@ -107,7 +107,7 @@ PHP_METHOD(vtiful_excel, __construct)
  */
 PHP_METHOD(vtiful_excel, fileName)
 {
-    zval rv, file_path, handle, *config, *tmp_path;
+    zval rv, file_path, handle, *dir_path;
     zend_string *file_name;
 
     ZEND_PARSE_PARAMETERS_START(1, 1)
@@ -116,10 +116,9 @@ PHP_METHOD(vtiful_excel, fileName)
 
     ZVAL_COPY(return_value, getThis());
 
-    config   = zend_read_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_COF), 0, &rv TSRMLS_DC);
-    tmp_path = zend_hash_str_find(Z_ARRVAL_P(config), V_EXCEL_PAT, sizeof(V_EXCEL_PAT)-1);
+    GET_CONFIG_PATH(dir_path, vtiful_excel_ce, return_value);
 
-    excel_file_path(file_name, tmp_path, &file_path);
+    excel_file_path(file_name, dir_path, &file_path);
 
     excel_res->workbook  = workbook_new(Z_STRVAL(file_path));
     excel_res->worksheet = workbook_add_worksheet(excel_res->workbook, NULL);
@@ -137,7 +136,7 @@ PHP_METHOD(vtiful_excel, fileName)
  */
 PHP_METHOD(vtiful_excel, constMemory)
 {
-    zval rv, file_path, handle, *config, *tmp_path;
+    zval file_path, handle, *dir_path;
     zend_string *file_name;
 
     ZEND_PARSE_PARAMETERS_START(1, 1)
@@ -146,10 +145,9 @@ PHP_METHOD(vtiful_excel, constMemory)
 
     ZVAL_COPY(return_value, getThis());
 
-    config   = zend_read_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_COF), 0, &rv TSRMLS_DC);
-    tmp_path = zend_hash_str_find(Z_ARRVAL_P(config), V_EXCEL_PAT, sizeof(V_EXCEL_PAT)-1);
+    GET_CONFIG_PATH(dir_path, vtiful_excel_ce, return_value);
 
-    excel_file_path(file_name, tmp_path, &file_path);
+    excel_file_path(file_name, dir_path, &file_path);
 
     lxw_workbook_options options = {.constant_memory = LXW_TRUE, .tmpdir = NULL};
 

+ 6 - 0
kernel/excel.h

@@ -18,6 +18,12 @@
 #define V_EXCEL_COF "config"
 #define V_EXCEL_PAT "path"
 
+#define GET_CONFIG_PATH(dir_path_res, class_name, object)                                             \
+    do {                                                                                              \
+        zval *_config  = zend_read_property(class_name, object, ZEND_STRL(V_EXCEL_COF), 0, NULL);     \
+        (dir_path_res) = zend_hash_str_find(Z_ARRVAL_P(_config), ZEND_STRL(V_EXCEL_PAT));             \
+    } while(0)
+
 extern zend_class_entry *vtiful_excel_ce;
 
 VTIFUL_STARTUP_FUNCTION(excel);

+ 0 - 5
kernel/exception.c

@@ -12,11 +12,6 @@
 
 #include "include.h"
 
-//#include <php.h>
-//#include "zend_exceptions.h"
-//#include "php_excel_writer.h"
-//#include "exception.h"
-
 zend_class_entry *vtiful_exception_ce;
 
 /** {{{ exception_methods