Browse Source

Feat(configure): enable reader

viest 5 years ago
parent
commit
3260fcf2f0

+ 23 - 9
config.m4

@@ -4,6 +4,9 @@ PHP_ARG_WITH(xlsxwriter, xlswriter support,
 PHP_ARG_WITH(libxlsxwriter, system libxlsswriter,
 PHP_ARG_WITH(libxlsxwriter, system libxlsswriter,
 [  --with-libxlsxwriter=DIR Use system library], no, no)
 [  --with-libxlsxwriter=DIR Use system library], no, no)
 
 
+PHP_ARG_ENABLE(reader, enable xlsx reader support,
+[  --enable-reader          Enable xlsx reader?], no, no)
+
 if test "$PHP_XLSWRITER" != "no"; then
 if test "$PHP_XLSWRITER" != "no"; then
     xls_writer_sources="
     xls_writer_sources="
     xlswriter.c \
     xlswriter.c \
@@ -14,7 +17,6 @@ if test "$PHP_XLSWRITER" != "no"; then
     kernel/write.c \
     kernel/write.c \
     kernel/format.c \
     kernel/format.c \
     kernel/chart.c \
     kernel/chart.c \
-    kernel/read.c \
     "
     "
     libxlsxwriter_sources="
     libxlsxwriter_sources="
     library/libxlsxwriter/third_party/minizip/ioapi.c \
     library/libxlsxwriter/third_party/minizip/ioapi.c \
@@ -65,6 +67,7 @@ if test "$PHP_XLSWRITER" != "no"; then
                 break
                 break
             fi
             fi
         done
         done
+
         if test -z "$XLSXWRITER_DIR"; then
         if test -z "$XLSXWRITER_DIR"; then
             AC_MSG_ERROR([libxlsxwriter library not found])
             AC_MSG_ERROR([libxlsxwriter library not found])
         else
         else
@@ -99,6 +102,7 @@ if test "$PHP_XLSWRITER" != "no"; then
                 -L$XLSXWRITER_DIR/$PHP_LIBDIR -lm
                 -L$XLSXWRITER_DIR/$PHP_LIBDIR -lm
             ])
             ])
         fi
         fi
+
         AC_DEFINE(HAVE_LIBXLSXWRITER, 1, [ use system libxlsxwriter ])
         AC_DEFINE(HAVE_LIBXLSXWRITER, 1, [ use system libxlsxwriter ])
     else
     else
         AC_MSG_RESULT([use the bundled library])
         AC_MSG_RESULT([use the bundled library])
@@ -122,15 +126,25 @@ if test "$PHP_XLSWRITER" != "no"; then
         LIBOPT="-DNOCRYPT -DNOUNCRYPT"
         LIBOPT="-DNOCRYPT -DNOUNCRYPT"
     fi
     fi
 
 
-    xls_writer_sources="$xls_writer_sources $libexpat"
-    PHP_ADD_INCLUDE([$srcdir/library/libexpat/expat/lib])
-    PHP_ADD_BUILD_DIR([$ext_builddir/library/libexpat/expat/lib])
-    LIBOPT="$LIBOPT -DXML_POOR_ENTROPY"
+    if test "$PHP_READER" = "yes"; then
+        xls_read_sources = "
+        kernel/read.c \
+        "
+
+        xls_writer_sources="$xls_writer_sources $xls_read_sources"
 
 
-    xls_writer_sources="$xls_writer_sources $libxlsxio"
-    PHP_ADD_INCLUDE([$srcdir/library/libxlsxio/include])
-    PHP_ADD_BUILD_DIR([$ext_builddir/library/libxlsxio/lib])
-    LIBOPT="$LIBOPT -DUSE_MINIZIP"
+        AC_DEFINE(ENABLE_READER, 1, [enable reader])
+
+        xls_writer_sources="$xls_writer_sources $libexpat $xls_read_sources"
+        PHP_ADD_INCLUDE([$srcdir/library/libexpat/expat/lib])
+        PHP_ADD_BUILD_DIR([$ext_builddir/library/libexpat/expat/lib])
+        LIBOPT="$LIBOPT -DXML_POOR_ENTROPY"
+
+        xls_writer_sources="$xls_writer_sources $libxlsxio"
+        PHP_ADD_INCLUDE([$srcdir/library/libxlsxio/include])
+        PHP_ADD_BUILD_DIR([$ext_builddir/library/libxlsxio/lib])
+        LIBOPT="$LIBOPT -DUSE_MINIZIP"
+    fi
 
 
     if test -z "$PHP_DEBUG"; then
     if test -z "$PHP_DEBUG"; then
         AC_ARG_ENABLE(debug, [--enable-debug compile with debugging system], [PHP_DEBUG=$enableval],[PHP_DEBUG=no])
         AC_ARG_ENABLE(debug, [--enable-debug compile with debugging system], [PHP_DEBUG=$enableval],[PHP_DEBUG=no])

+ 18 - 9
include/xlswriter.h

@@ -28,15 +28,29 @@
 #include "xlsxwriter/packager.h"
 #include "xlsxwriter/packager.h"
 #include "xlsxwriter/format.h"
 #include "xlsxwriter/format.h"
 
 
-#include "xlsxio_read.h"
-
 #include "php_xlswriter.h"
 #include "php_xlswriter.h"
 #include "excel.h"
 #include "excel.h"
 #include "exception.h"
 #include "exception.h"
 #include "format.h"
 #include "format.h"
 #include "chart.h"
 #include "chart.h"
+
+#ifdef ENABLE_READER
+#include "xlsxio_read.h"
 #include "read.h"
 #include "read.h"
 
 
+typedef struct {
+    xlsxioreader      file_t;
+    xlsxioreadersheet sheet_t;
+} xls_resource_read_t;
+#endif
+
+#ifndef ENABLE_READER
+typedef struct {
+    void * file_t;
+    void * sheet_t;
+} xls_resource_read_t;
+#endif
+
 enum xlswriter_boolean {
 enum xlswriter_boolean {
     XLSWRITER_FALSE,
     XLSWRITER_FALSE,
     XLSWRITER_TRUE
     XLSWRITER_TRUE
@@ -56,11 +70,6 @@ typedef struct {
     lxw_chart_series *series;
     lxw_chart_series *series;
 } xls_resource_chart_t;
 } xls_resource_chart_t;
 
 
-typedef struct {
-    xlsxioreader      file_t;
-    xlsxioreadersheet sheet_t;
-} xls_resource_read_t;
-
 typedef struct _vtiful_xls_object {
 typedef struct _vtiful_xls_object {
     xls_resource_read_t  read_ptr;
     xls_resource_read_t  read_ptr;
     xls_resource_write_t write_ptr;
     xls_resource_write_t write_ptr;
@@ -124,8 +133,8 @@ static inline chart_object *php_vtiful_chart_fetch_object(zend_object *obj) {
 #endif
 #endif
 
 
 lxw_format           * zval_get_format(zval *handle);
 lxw_format           * zval_get_format(zval *handle);
-xls_resource_write_t       * zval_get_resource(zval *handle);
-xls_resource_chart_t *zval_get_chart(zval *resource);
+xls_resource_write_t * zval_get_resource(zval *handle);
+xls_resource_chart_t * zval_get_chart(zval *resource);
 
 
 STATIC lxw_error _store_defined_name(lxw_workbook *self, const char *name, const char *app_name, const char *formula, int16_t index, uint8_t hidden);
 STATIC lxw_error _store_defined_name(lxw_workbook *self, const char *name, const char *app_name, const char *formula, int16_t index, uint8_t hidden);
 
 

+ 10 - 1
kernel/excel.c

@@ -50,8 +50,10 @@ static void vtiful_xls_objects_free(zend_object *object)
 
 
     lxw_workbook_free(intern->write_ptr.workbook);
     lxw_workbook_free(intern->write_ptr.workbook);
 
 
+#ifdef ENABLE_READER
     xlsxioread_sheet_close(intern->read_ptr.sheet_t);
     xlsxioread_sheet_close(intern->read_ptr.sheet_t);
     xlsxioread_close(intern->read_ptr.file_t);
     xlsxioread_close(intern->read_ptr.file_t);
+#endif
 
 
     zend_object_std_dtor(&intern->zo);
     zend_object_std_dtor(&intern->zo);
 }
 }
@@ -622,6 +624,8 @@ PHP_METHOD(vtiful_xls, setRow)
 }
 }
 /* }}} */
 /* }}} */
 
 
+#ifdef ENABLE_READER
+
 /** {{{ \Vtiful\Kernel\xls::openFile()
 /** {{{ \Vtiful\Kernel\xls::openFile()
  */
  */
 PHP_METHOD(vtiful_xls, openFile)
 PHP_METHOD(vtiful_xls, openFile)
@@ -694,6 +698,8 @@ PHP_METHOD(vtiful_xls, nextRow)
 }
 }
 /* }}} */
 /* }}} */
 
 
+#endif
+
 /** {{{ xls_methods
 /** {{{ xls_methods
 */
 */
 zend_function_entry xls_methods[] = {
 zend_function_entry xls_methods[] = {
@@ -715,10 +721,13 @@ zend_function_entry xls_methods[] = {
         PHP_ME(vtiful_xls, mergeCells,    xls_merge_cells_arginfo,    ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_xls, mergeCells,    xls_merge_cells_arginfo,    ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_xls, setColumn,     xls_set_column_arginfo,     ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_xls, setColumn,     xls_set_column_arginfo,     ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_xls, setRow,        xls_set_row_arginfo,        ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_xls, setRow,        xls_set_row_arginfo,        ZEND_ACC_PUBLIC)
+
+#ifdef ENABLE_READER
         PHP_ME(vtiful_xls, openFile,      NULL,                       ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_xls, openFile,      NULL,                       ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_xls, openSheet,     NULL,                       ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_xls, openSheet,     NULL,                       ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_xls, getSheetData,  NULL,                       ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_xls, getSheetData,  NULL,                       ZEND_ACC_PUBLIC)
-        //PHP_ME(vtiful_xls, nextRow,       NULL, ZEND_ACC_PUBLIC)
+#endif
+
         PHP_FE_END
         PHP_FE_END
 };
 };
 /* }}} */
 /* }}} */

+ 21 - 0
tests/include/skipif.inc

@@ -0,0 +1,21 @@
+<?php
+
+/**
+ * Skip Disable Reader
+ *
+ * @return void
+ *
+ * @author viest
+ */
+function skip_disable_reader() {
+    if (!method_exists('\Vtiful\Kernel\Excel', 'openFile')) {
+        print "skip";
+    }
+}
+
+(function(){
+    if (!extension_loaded("xlswriter")) {
+        print "skip";
+    }
+})();
+

+ 4 - 1
tests/open_xlsx_file.phpt

@@ -1,7 +1,10 @@
 --TEST--
 --TEST--
 Check for vtiful presence
 Check for vtiful presence
 --SKIPIF--
 --SKIPIF--
-<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
+<?php
+require __DIR__ . '/include/skipif.inc';
+skip_disable_reader();
+?>
 --FILE--
 --FILE--
 <?php
 <?php
 $config   = ['path' => './tests'];
 $config   = ['path' => './tests'];

+ 4 - 1
tests/open_xlsx_get_data.phpt

@@ -1,7 +1,10 @@
 --TEST--
 --TEST--
 Check for vtiful presence
 Check for vtiful presence
 --SKIPIF--
 --SKIPIF--
-<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
+<?php
+require __DIR__ . '/include/skipif.inc';
+skip_disable_reader();
+?>
 --FILE--
 --FILE--
 <?php
 <?php
 $config   = ['path' => './tests'];
 $config   = ['path' => './tests'];

+ 4 - 1
tests/open_xlsx_get_sheet_not_found_data.phpt

@@ -1,7 +1,10 @@
 --TEST--
 --TEST--
 Check for vtiful presence
 Check for vtiful presence
 --SKIPIF--
 --SKIPIF--
-<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
+<?php
+require __DIR__ . '/include/skipif.inc';
+skip_disable_reader();
+?>
 --FILE--
 --FILE--
 <?php
 <?php
 $config   = ['path' => './tests'];
 $config   = ['path' => './tests'];

+ 4 - 1
tests/open_xlsx_sheet.phpt

@@ -1,7 +1,10 @@
 --TEST--
 --TEST--
 Check for vtiful presence
 Check for vtiful presence
 --SKIPIF--
 --SKIPIF--
-<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
+<?php
+require __DIR__ . '/include/skipif.inc';
+skip_disable_reader();
+?>
 --FILE--
 --FILE--
 <?php
 <?php
 $config   = ['path' => './tests'];
 $config   = ['path' => './tests'];