Explorar el Código

Merge pull request #318 from viest/dev

Feat: protection
viest hace 4 años
padre
commit
b207bc1e6c
Se han modificado 7 ficheros con 98 adiciones y 11 borrados
  1. 1 0
      .gitignore
  2. 1 0
      include/xlswriter.h
  3. 25 0
      kernel/excel.c
  4. 12 0
      kernel/write.c
  5. 29 10
      package.xml
  6. 1 1
      php_xlswriter.h
  7. 29 0
      tests/protection.phpt

+ 1 - 0
.gitignore

@@ -45,3 +45,4 @@ cmake-build-debug
 CMakeLists.txt
 local_test.php
 xlswriter-*.tgz
+benchmark.c

+ 1 - 0
include/xlswriter.h

@@ -211,6 +211,7 @@ void comment_show(xls_resource_write_t *res);
 void zoom(xls_resource_write_t *res, zend_long zoom);
 void gridlines(xls_resource_write_t *res, zend_long option);
 void auto_filter(zend_string *range, xls_resource_write_t *res);
+void protection(xls_resource_write_t *res, zend_string *password);
 void format_copy(lxw_format *new_format, lxw_format *other_format);
 void xls_file_path(zend_string *file_name, zval *dir_path, zval *file_path);
 void freeze_panes(xls_resource_write_t *res, zend_long row, zend_long column);

+ 25 - 0
kernel/excel.c

@@ -261,6 +261,10 @@ ZEND_END_ARG_INFO()
 ZEND_BEGIN_ARG_INFO_EX(xls_sheet_zoom_arginfo, 0, 0, 1)
                 ZEND_ARG_INFO(0, scale)
 ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(xls_protection_arginfo, 0, 0, 0)
+                ZEND_ARG_INFO(0, password)
+ZEND_END_ARG_INFO()
 /* }}} */
 
 /** {{{ \Vtiful\Kernel\Excel::__construct(array $config)
@@ -1078,6 +1082,25 @@ PHP_METHOD(vtiful_xls, zoom)
 }
 /* }}} */
 
+/** {{{ \Vtiful\Kernel\Excel::protection(string $password)
+ */
+PHP_METHOD(vtiful_xls, protection)
+{
+    zend_string *password = NULL;
+
+    ZEND_PARSE_PARAMETERS_START(0, 1)
+            Z_PARAM_OPTIONAL
+            Z_PARAM_STR(password)
+    ZEND_PARSE_PARAMETERS_END();
+
+    ZVAL_COPY(return_value, getThis());
+
+    xls_object* obj = Z_XLS_P(getThis());
+
+    protection(&obj->write_ptr, password);
+}
+/* }}} */
+
 #ifdef ENABLE_READER
 
 /** {{{ \Vtiful\Kernel\Excel::openFile()
@@ -1391,6 +1414,8 @@ zend_function_entry xls_methods[] = {
         PHP_ME(vtiful_xls, defaultFormat, xls_set_global_format,      ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_xls, freezePanes,   xls_freeze_panes_arginfo,   ZEND_ACC_PUBLIC)
 
+        PHP_ME(vtiful_xls, protection,    xls_protection_arginfo,     ZEND_ACC_PUBLIC)
+
         PHP_ME(vtiful_xls, zoom,          xls_sheet_zoom_arginfo,     ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_xls, gridline,      xls_sheet_gridline_arginfo, ZEND_ACC_PUBLIC)
 

+ 12 - 0
kernel/write.c

@@ -339,6 +339,18 @@ void zoom(xls_resource_write_t *res, zend_long zoom)
     worksheet_set_zoom(res->worksheet, zoom);
 }
 
+/*
+ * Set the worksheet protection
+ */
+void protection(xls_resource_write_t *res, zend_string *password)
+{
+    if (password == NULL) {
+        worksheet_protect(res->worksheet, NULL, NULL);
+    } else {
+        worksheet_protect(res->worksheet, ZSTR_VAL(password), NULL);
+    }
+}
+
 /*
  * Call finalization code and close file.
  */

+ 29 - 10
package.xml

@@ -33,11 +33,11 @@
   <email>[email protected]</email>
   <active>yes</active>
  </lead>
- <date>2020-06-17</date>
- <time>01:37:24</time>
+ <date>2020-08-18</date>
+ <time>18:00:00</time>
  <version>
-  <release>1.3.6</release>
-  <api>1.3.6</api>
+  <release>1.3.7</release>
+  <api>1.3.7</api>
  </version>
  <stability>
   <release>stable</release>
@@ -45,11 +45,10 @@
  </stability>
  <license uri="https://github.com/viest/php-ext-excel-export/blob/master/LICENSE">BSD license</license>
  <notes>
-- Fix musllibc.
-- Fix null in cell callback.
-- Feat cell comment.
-- Feat timestampFromDateDouble static method.
-- Feat Check for existence before opening file.
+- Fix IBM s390x.
+- Fix header line no and sheet checkout not init line no.
+- Feat set global type.
+- Feat url text and tool tip.
  </notes>
  <contents>
   <dir name="/">
@@ -283,6 +282,26 @@
   <configureoption default="yes" name="enable-reader" prompt="enable reader supports?" />
  </extsrcrelease>
  <changelog>
+  <release>
+   <date>2020-06-17</date>
+   <time>01:37:24</time>
+   <version>
+    <release>1.3.6</release>
+    <api>1.3.6</api>
+   </version>
+   <stability>
+    <release>stable</release>
+    <api>stable</api>
+   </stability>
+   <license uri="https://github.com/viest/php-ext-excel-export/blob/master/LICENSE">BSD license</license>
+   <notes>
+    - Fix musllibc.
+    - Fix null in cell callback.
+    - Feat cell comment.
+    - Feat timestampFromDateDouble static method.
+    - Feat Check for existence before opening file.
+   </notes>
+  </release>
   <release>
    <date>2020-06-08</date>
    <time>14:22:09</time>
@@ -332,7 +351,7 @@
    <notes>
 - FEAT header support custom format.
 - FEAT putcsv custom delimiter.
-- FEAT ead skip cells,rows,empty value.
+- FEAT read skip cells,rows,empty value.
 - FIX read data method, the offset of the array index and the row of the cell.
 - FIX insertDate leaked.
    </notes>

+ 1 - 1
php_xlswriter.h

@@ -18,7 +18,7 @@
 extern zend_module_entry xlswriter_module_entry;
 #define phpext_xlswriter_ptr &xlswriter_module_entry
 
-#define PHP_XLSWRITER_VERSION "1.3.6"
+#define PHP_XLSWRITER_VERSION "1.3.7"
 
 #ifdef PHP_WIN32
 #	define PHP_VTIFUL_API __declspec(dllexport)

+ 29 - 0
tests/protection.phpt

@@ -0,0 +1,29 @@
+--TEST--
+Check for vtiful presence
+--SKIPIF--
+<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
+--FILE--
+<?php
+$config = [
+    'path' => './tests'
+];
+
+$fileObject = new \Vtiful\Kernel\Excel($config);
+$fileObject = $fileObject->fileName('tutorial.xlsx');
+
+$filePath = $fileObject->header(['name', 'age'])
+    ->data([
+        ['viest', 21],
+        ['wjx',   21]
+    ])
+    ->protection()
+    ->output();
+
+var_dump($filePath);
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/tutorial.xlsx');
+?>
+--EXPECT--
+string(21) "./tests/tutorial.xlsx"