| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462 | 
							- /*
 
-   +----------------------------------------------------------------------+
 
-   | Vtiful Extension                                                     |
 
-   +----------------------------------------------------------------------+
 
-   | Copyright (c) 2017-2017 The Viest                                    |
 
-   +----------------------------------------------------------------------+
 
-   | http://www.viest.me                                                  |
 
-   +----------------------------------------------------------------------+
 
-   | Author: viest <[email protected]>                                 |
 
-   +----------------------------------------------------------------------+
 
- */
 
- #ifdef HAVE_CONFIG_H
 
- #include "config.h"
 
- #endif
 
- #include "include.h"
 
- zend_class_entry *vtiful_excel_ce;
 
- /* {{{ ARG_INFO
 
-  */
 
- ZEND_BEGIN_ARG_INFO_EX(excel_construct_arginfo, 0, 0, 1)
 
-                 ZEND_ARG_INFO(0, config)
 
- ZEND_END_ARG_INFO()
 
- ZEND_BEGIN_ARG_INFO_EX(excel_file_name_arginfo, 0, 0, 1)
 
-                 ZEND_ARG_INFO(0, file_name)
 
- ZEND_END_ARG_INFO()
 
- ZEND_BEGIN_ARG_INFO_EX(excel_header_arginfo, 0, 0, 1)
 
-                 ZEND_ARG_INFO(0, header)
 
- ZEND_END_ARG_INFO()
 
- ZEND_BEGIN_ARG_INFO_EX(excel_data_arginfo, 0, 0, 1)
 
-                 ZEND_ARG_INFO(0, data)
 
- ZEND_END_ARG_INFO()
 
- ZEND_BEGIN_ARG_INFO_EX(excel_insert_text_arginfo, 0, 0, 4)
 
-                 ZEND_ARG_INFO(0, row)
 
-                 ZEND_ARG_INFO(0, column)
 
-                 ZEND_ARG_INFO(0, data)
 
-                 ZEND_ARG_INFO(0, format)
 
- ZEND_END_ARG_INFO()
 
- ZEND_BEGIN_ARG_INFO_EX(excel_insert_image_arginfo, 0, 0, 3)
 
-                 ZEND_ARG_INFO(0, row)
 
-                 ZEND_ARG_INFO(0, column)
 
-                 ZEND_ARG_INFO(0, image)
 
- ZEND_END_ARG_INFO()
 
- ZEND_BEGIN_ARG_INFO_EX(excel_insert_formula_arginfo, 0, 0, 3)
 
-                 ZEND_ARG_INFO(0, row)
 
-                 ZEND_ARG_INFO(0, column)
 
-                 ZEND_ARG_INFO(0, formula)
 
- ZEND_END_ARG_INFO()
 
- ZEND_BEGIN_ARG_INFO_EX(excel_auto_filter_arginfo, 0, 0, 1)
 
-                 ZEND_ARG_INFO(0, range)
 
- ZEND_END_ARG_INFO()
 
- ZEND_BEGIN_ARG_INFO_EX(excel_merge_cells_arginfo, 0, 0, 2)
 
-                 ZEND_ARG_INFO(0, range)
 
-                 ZEND_ARG_INFO(0, data)
 
- ZEND_END_ARG_INFO()
 
- ZEND_BEGIN_ARG_INFO_EX(excel_set_column_arginfo, 0, 0, 3)
 
-                 ZEND_ARG_INFO(0, format_handle)
 
-                 ZEND_ARG_INFO(0, range)
 
-                 ZEND_ARG_INFO(0, width)
 
- ZEND_END_ARG_INFO()
 
- ZEND_BEGIN_ARG_INFO_EX(excel_set_row_arginfo, 0, 0, 3)
 
-                 ZEND_ARG_INFO(0, format_handle)
 
-                 ZEND_ARG_INFO(0, range)
 
-                 ZEND_ARG_INFO(0, height)
 
- ZEND_END_ARG_INFO()
 
- /* }}} */
 
- /** {{{ \Vtiful\Kernel\Excel::__construct(array $config)
 
-  */
 
- PHP_METHOD(vtiful_excel, __construct)
 
- {
 
-     zval *config, *c_path;
 
-     ZEND_PARSE_PARAMETERS_START(1, 1)
 
-             Z_PARAM_ARRAY(config)
 
-     ZEND_PARSE_PARAMETERS_END();
 
-     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;
 
-     }
 
-     if(Z_TYPE_P(c_path) != IS_STRING)
 
-     {
 
-         zend_throw_exception(vtiful_exception_ce, "Configure 'path' must be a string type", 120);
 
-         return;
 
-     }
 
-     zend_update_property(vtiful_excel_ce, getThis(), ZEND_STRL(V_EXCEL_COF), config);
 
- }
 
- /* }}} */
 
- /** {{{ \Vtiful\Kernel\Excel::filename(string $fileName)
 
-  */
 
- PHP_METHOD(vtiful_excel, fileName)
 
- {
 
-     zval rv, file_path, handle, *dir_path;
 
-     zend_string *file_name;
 
-     ZEND_PARSE_PARAMETERS_START(1, 1)
 
-             Z_PARAM_STR(file_name)
 
-     ZEND_PARSE_PARAMETERS_END();
 
-     ZVAL_COPY(return_value, getThis());
 
-     GET_CONFIG_PATH(dir_path, vtiful_excel_ce, return_value);
 
-     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);
 
-     ZVAL_RES(&handle, zend_register_resource(excel_res, le_excel_writer));
 
-     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);
 
- }
 
- /* }}} */
 
- /** {{{ \Vtiful\Kernel\Excel::constMemory(string $fileName)
 
-  */
 
- PHP_METHOD(vtiful_excel, constMemory)
 
- {
 
-     zval file_path, handle, *dir_path;
 
-     zend_string *file_name;
 
-     ZEND_PARSE_PARAMETERS_START(1, 1)
 
-             Z_PARAM_STR(file_name)
 
-     ZEND_PARSE_PARAMETERS_END();
 
-     ZVAL_COPY(return_value, getThis());
 
-     GET_CONFIG_PATH(dir_path, vtiful_excel_ce, return_value);
 
-     excel_file_path(file_name, dir_path, &file_path);
 
-     lxw_workbook_options options = {.constant_memory = LXW_TRUE, .tmpdir = NULL};
 
-     excel_res->workbook  = workbook_new_opt(Z_STRVAL(file_path), &options);
 
-     excel_res->worksheet = workbook_add_worksheet(excel_res->workbook, NULL);
 
-     ZVAL_RES(&handle, zend_register_resource(excel_res, le_excel_writer));
 
-     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);
 
- }
 
- /* }}} */
 
- /** {{{ \Vtiful\Kernel\Excel::header(array $header)
 
-  */
 
- PHP_METHOD(vtiful_excel, header)
 
- {
 
-     zval res_handle, *header, *header_value;
 
-     zend_long header_l_key;
 
-     ZEND_PARSE_PARAMETERS_START(1, 1)
 
-             Z_PARAM_ARRAY(header)
 
-     ZEND_PARSE_PARAMETERS_END();
 
-     ZVAL_COPY(return_value, getThis());
 
-     ZEND_HASH_FOREACH_NUM_KEY_VAL(Z_ARRVAL_P(header), header_l_key, header_value) {
 
-          type_writer(header_value, 0, header_l_key, excel_res, NULL);
 
-          zval_ptr_dtor(header_value);
 
-     } ZEND_HASH_FOREACH_END();
 
-     ZVAL_RES(&res_handle, zend_register_resource(excel_res, le_excel_writer));
 
-     zend_update_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_HANDLE), &res_handle);
 
- }
 
- /* }}} */
 
- /** {{{ \Vtiful\Kernel\Excel::data(array $data)
 
-  */
 
- PHP_METHOD(vtiful_excel, data)
 
- {
 
-     zval *data, res_handle, *data_r_value, *data_l_value;
 
-     zend_long data_r_key, data_l_key;
 
-     ZEND_PARSE_PARAMETERS_START(1, 1)
 
-             Z_PARAM_ARRAY(data)
 
-     ZEND_PARSE_PARAMETERS_END();
 
-     ZVAL_COPY(return_value, getThis());
 
-     ZEND_HASH_FOREACH_NUM_KEY_VAL(Z_ARRVAL_P(data), data_r_key, data_r_value) {
 
-         if(Z_TYPE_P(data_r_value) == IS_ARRAY) {
 
-             ZEND_HASH_FOREACH_NUM_KEY_VAL(Z_ARRVAL_P(data_r_value), data_l_key, data_l_value) {
 
-                 type_writer(data_l_value, data_r_key+1, data_l_key, excel_res, NULL);
 
-                 zval_ptr_dtor(data_l_value);
 
-             } ZEND_HASH_FOREACH_END();
 
-         }
 
-     } ZEND_HASH_FOREACH_END();
 
-     ZVAL_RES(&res_handle, zend_register_resource(excel_res, le_excel_writer));
 
-     zend_update_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_HANDLE), &res_handle);
 
- }
 
- /* }}} */
 
- /** {{{ \Vtiful\Kernel\Excel::output()
 
-  */
 
- PHP_METHOD(vtiful_excel, output)
 
- {
 
-     zval rv, null_handle, *handle, *file_path;
 
-     handle    = zend_read_property(vtiful_excel_ce, getThis(), ZEND_STRL(V_EXCEL_HANDLE), 0, &rv TSRMLS_DC);
 
-     file_path = zend_read_property(vtiful_excel_ce, getThis(), ZEND_STRL(V_EXCEL_FIL), 0, &rv TSRMLS_DC);
 
-     workbook_file(excel_res, handle);
 
-     free(excel_res);
 
-     ZVAL_NULL(&null_handle);
 
-     zend_update_property(vtiful_excel_ce, getThis(), ZEND_STRL(V_EXCEL_HANDLE), &null_handle);
 
-     ZVAL_COPY(return_value, file_path);
 
- }
 
- /* }}} */
 
- /** {{{ \Vtiful\Kernel\Excel::getHandle()
 
-  */
 
- PHP_METHOD(vtiful_excel, getHandle)
 
- {
 
-     zval rv;
 
-     zval *handle;
 
-     handle = zend_read_property(vtiful_excel_ce, getThis(), ZEND_STRL(V_EXCEL_HANDLE), 0, &rv TSRMLS_DC);
 
-     ZVAL_COPY(return_value, handle);
 
- }
 
- /* }}} */
 
- /** {{{ \Vtiful\Kernel\Excel::insertText(int $row, int $column, string|int|double $data)
 
-  */
 
- PHP_METHOD(vtiful_excel, insertText)
 
- {
 
-     zval res_handle;
 
-     zval *data;
 
-     zend_long row, column;
 
-     zend_string *format = NULL;
 
-     ZEND_PARSE_PARAMETERS_START(3, 4)
 
-             Z_PARAM_LONG(row)
 
-             Z_PARAM_LONG(column)
 
-             Z_PARAM_ZVAL(data)
 
-             Z_PARAM_OPTIONAL
 
-             Z_PARAM_STR(format)
 
-     ZEND_PARSE_PARAMETERS_END();
 
-     ZVAL_COPY(return_value, getThis());
 
-     type_writer(data, row, column, excel_res, format);
 
-     ZVAL_RES(&res_handle, zend_register_resource(excel_res, le_excel_writer));
 
-     zend_update_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_HANDLE), &res_handle);
 
- }
 
- /* }}} */
 
- /** {{{ \Vtiful\Kernel\Excel::insertImage(int $row, int $column, string $imagePath)
 
-  */
 
- PHP_METHOD(vtiful_excel, insertImage)
 
- {
 
-     zval res_handle;
 
-     zval *image;
 
-     zend_long row, column;
 
-     ZEND_PARSE_PARAMETERS_START(3, 3)
 
-             Z_PARAM_LONG(row)
 
-             Z_PARAM_LONG(column)
 
-             Z_PARAM_ZVAL(image)
 
-     ZEND_PARSE_PARAMETERS_END();
 
-     ZVAL_COPY(return_value, getThis());
 
-     image_writer(image, row, column, excel_res);
 
-     ZVAL_RES(&res_handle, zend_register_resource(excel_res, le_excel_writer));
 
-     zend_update_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_HANDLE), &res_handle);
 
- }
 
- /* }}} */
 
- /** {{{ \Vtiful\Kernel\Excel::insertImage(int $row, int $column, string $imagePath)
 
-  */
 
- PHP_METHOD(vtiful_excel, insertFormula)
 
- {
 
-     zval res_handle;
 
-     zval *formula;
 
-     zend_long row, column;
 
-     ZEND_PARSE_PARAMETERS_START(3, 3)
 
-             Z_PARAM_LONG(row)
 
-             Z_PARAM_LONG(column)
 
-             Z_PARAM_ZVAL(formula)
 
-     ZEND_PARSE_PARAMETERS_END();
 
-     ZVAL_COPY(return_value, getThis());
 
-     formula_writer(formula, row, column, excel_res);
 
-     ZVAL_RES(&res_handle, zend_register_resource(excel_res, le_excel_writer));
 
-     zend_update_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_HANDLE), &res_handle);
 
- }
 
- /* }}} */
 
- /** {{{ \Vtiful\Kernel\Excel::autoFilter(int $rowStart, int $rowEnd, int $columnStart, int $columnEnd)
 
-  */
 
- PHP_METHOD(vtiful_excel, autoFilter)
 
- {
 
-     zval res_handle;
 
-     zend_string *range;
 
-     ZEND_PARSE_PARAMETERS_START(1, 1)
 
-             Z_PARAM_STR(range)
 
-     ZEND_PARSE_PARAMETERS_END();
 
-     ZVAL_COPY(return_value, getThis());
 
-     auto_filter(range, excel_res);
 
-     ZVAL_RES(&res_handle, zend_register_resource(excel_res, le_excel_writer));
 
-     zend_update_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_HANDLE), &res_handle);
 
- }
 
- /* }}} */
 
- /** {{{ \Vtiful\Kernel\Excel::mergeCells(string $range, string $data)
 
-  */
 
- PHP_METHOD(vtiful_excel, mergeCells)
 
- {
 
-     zval res_handle;
 
-     zend_string *range, *data;
 
-     ZEND_PARSE_PARAMETERS_START(2, 2)
 
-             Z_PARAM_STR(range)
 
-             Z_PARAM_STR(data)
 
-     ZEND_PARSE_PARAMETERS_END();
 
-     ZVAL_COPY(return_value, getThis());
 
-     merge_cells(range, data, excel_res);
 
-     ZVAL_RES(&res_handle, zend_register_resource(excel_res, le_excel_writer));
 
-     zend_update_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_HANDLE), &res_handle);
 
- }
 
- /* }}} */
 
- /** {{{ \Vtiful\Kernel\Excel::setColumn(resource $format, string $range [, int $width])
 
-  */
 
- PHP_METHOD(vtiful_excel, setColumn)
 
- {
 
-     zval *format_handle, res_handle;
 
-     zend_string *range;
 
-     double width = 0;
 
-     int    argc  = ZEND_NUM_ARGS();
 
-     ZEND_PARSE_PARAMETERS_START(2, 3)
 
-             Z_PARAM_RESOURCE(format_handle)
 
-             Z_PARAM_STR(range)
 
-             Z_PARAM_OPTIONAL
 
-             Z_PARAM_DOUBLE(width)
 
-     ZEND_PARSE_PARAMETERS_END();
 
-     ZVAL_COPY(return_value, getThis());
 
-     if (argc == 2) {
 
-         width = 10;
 
-     }
 
-     set_column(range, width, excel_res, zval_get_format(format_handle));
 
-     ZVAL_RES(&res_handle, zend_register_resource(excel_res, le_excel_writer));
 
-     zend_update_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_HANDLE), &res_handle);
 
- }
 
- /* }}} */
 
- /** {{{ \Vtiful\Kernel\Excel::setRow(resource $format, string $range [, int $heitght])
 
-  */
 
- PHP_METHOD(vtiful_excel, setRow)
 
- {
 
-     zval *format_handle, res_handle;
 
-     zend_string *range;
 
-     double height = 0;
 
-     int    argc  = ZEND_NUM_ARGS();
 
-     ZEND_PARSE_PARAMETERS_START(2, 3)
 
-             Z_PARAM_RESOURCE(format_handle)
 
-             Z_PARAM_STR(range)
 
-             Z_PARAM_OPTIONAL
 
-             Z_PARAM_DOUBLE(height)
 
-     ZEND_PARSE_PARAMETERS_END();
 
-     ZVAL_COPY(return_value, getThis());
 
-     if (argc == 2) {
 
-         height = 18;
 
-     }
 
-     set_row(range, height, excel_res, zval_get_format(format_handle));
 
-     ZVAL_RES(&res_handle, zend_register_resource(excel_res, le_excel_writer));
 
-     zend_update_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_HANDLE), &res_handle);
 
- }
 
- /* }}} */
 
- /** {{{ excel_methods
 
- */
 
- 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, constMemory,   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_ME(vtiful_excel, autoFilter,    excel_auto_filter_arginfo,    ZEND_ACC_PUBLIC)
 
-         PHP_ME(vtiful_excel, insertText,    excel_insert_text_arginfo,    ZEND_ACC_PUBLIC)
 
-         PHP_ME(vtiful_excel, insertImage,   excel_insert_image_arginfo,   ZEND_ACC_PUBLIC)
 
-         PHP_ME(vtiful_excel, insertFormula, excel_insert_formula_arginfo, ZEND_ACC_PUBLIC)
 
-         PHP_ME(vtiful_excel, mergeCells,    excel_merge_cells_arginfo,    ZEND_ACC_PUBLIC)
 
-         PHP_ME(vtiful_excel, setColumn,     excel_set_column_arginfo,     ZEND_ACC_PUBLIC)
 
-         PHP_ME(vtiful_excel, setRow,        excel_set_row_arginfo,        ZEND_ACC_PUBLIC)
 
-         PHP_FE_END
 
- };
 
- /* }}} */
 
- /** {{{ VTIFUL_STARTUP_FUNCTION
 
- */
 
- VTIFUL_STARTUP_FUNCTION(excel) {
 
-     zend_class_entry ce;
 
-     INIT_NS_CLASS_ENTRY(ce, "Vtiful\\Kernel", "Excel", excel_methods);
 
-     vtiful_excel_ce = zend_register_internal_class(&ce);
 
-     REGISTER_CLASS_PROPERTY_NULL(vtiful_excel_ce, V_EXCEL_COF,    ZEND_ACC_PRIVATE);
 
-     REGISTER_CLASS_PROPERTY_NULL(vtiful_excel_ce, V_EXCEL_FIL,    ZEND_ACC_PRIVATE);
 
-     REGISTER_CLASS_PROPERTY_NULL(vtiful_excel_ce, V_EXCEL_HANDLE, ZEND_ACC_PRIVATE);
 
-     return SUCCESS;
 
- }
 
- /* }}} */
 
 
  |