Browse Source

project init

viest 7 years ago
commit
e8b993e214
12 changed files with 458 additions and 0 deletions
  1. 39 0
      .gitignore
  2. 1 0
      CREDITS
  3. 0 0
      EXPERIMENTAL
  4. 40 0
      config.m4
  5. 13 0
      config.w32
  6. 108 0
      kernel/excel.c
  7. 12 0
      kernel/excel.h
  8. 20 0
      kernel/exception.c
  9. 8 0
      kernel/exception.h
  10. 55 0
      php_vtiful.h
  11. 10 0
      tests/001.phpt
  12. 152 0
      vtiful.c

+ 39 - 0
.gitignore

@@ -0,0 +1,39 @@
+.deps
+*.lo
+*.la
+.libs
+acinclude.m4
+aclocal.m4
+autom4te.cache
+build
+config.guess
+config.h
+config.h.in
+config.log
+config.nice
+config.status
+config.sub
+configure
+configure.in
+include
+install-sh
+libtool
+ltmain.sh
+Makefile
+Makefile.fragments
+Makefile.global
+Makefile.objects
+missing
+mkinstalldirs
+modules
+run-tests.php
+tests/*/*.diff
+tests/*/*.out
+tests/*/*.php
+tests/*/*.exp
+tests/*/*.log
+tests/*/*.sh
+.idea
+cmake-build-debug
+CMakeLists.txt
+local_test.php

+ 1 - 0
CREDITS

@@ -0,0 +1 @@
+vtiful

+ 0 - 0
EXPERIMENTAL


+ 40 - 0
config.m4

@@ -0,0 +1,40 @@
+PHP_ARG_ENABLE(vtiful, whether to enable vtiful support,
+[  --enable-vtiful           Enable vtiful support])
+
+if test "$PHP_VTIFUL" != "no"; then
+    vtiful_sources="vtiful.c \
+    kernel/exception.c \
+    "
+
+    AC_MSG_CHECKING([Check libxlsxwriter support])
+
+    for i in /usr/local /usr; do
+        if test -r $i/include/xlsxwriter.h; then
+            AC_MSG_CHECKING([Check libxlsxwriter library])
+            XLSXWRITER_DIR=$i
+            PHP_ADD_INCLUDE($i/include)
+            PHP_CHECK_LIBRARY(xlsxwriter, worksheet_write_string,
+            [
+                PHP_ADD_LIBRARY_WITH_PATH(xlsxwriter, $i/$PHP_LIBDIR, VTIFUL_SHARED_LIBADD)
+                AC_DEFINE([VTIFUL_XLSX_WRITER], [1], [Have libxlsxwriter support])
+                vtiful_sources="$vtiful_sources kernel/excel.c "
+            ],[
+                AC_MSG_ERROR([Wrong libxlsxwriter version or library not found])
+            ],[
+                -L$i/$PHP_LIBDIR -lm
+            ])
+
+            break
+        else
+            AC_MSG_RESULT([no, found in $i])
+        fi
+    done
+
+    if test -z "$XLSXWRITER_DIR"; then
+        AC_MSG_ERROR([libxlsxwriter library not found])
+    fi
+
+    PHP_SUBST(VTIFUL_SHARED_LIBADD)
+
+    PHP_NEW_EXTENSION(vtiful, $vtiful_sources, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
+fi

+ 13 - 0
config.w32

@@ -0,0 +1,13 @@
+// $Id$
+// vim:ft=javascript
+
+// If your extension references something external, use ARG_WITH
+// ARG_WITH("vtiful", "for vtiful support", "no");
+
+// Otherwise, use ARG_ENABLE
+// ARG_ENABLE("vtiful", "enable vtiful support", "no");
+
+if (PHP_VTIFUL != "no") {
+	EXTENSION("vtiful", "vtiful.c", PHP_EXTNAME_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
+}
+

+ 108 - 0
kernel/excel.c

@@ -0,0 +1,108 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "zend.h"
+#include "zend_API.h"
+#include "zend_exceptions.h"
+
+#include "php.h"
+
+#include "xlsxwriter.h"
+#include "php_vtiful.h"
+#include "excel.h"
+#include "exception.h"
+
+#include "ext/standard/php_var.h"
+
+typedef struct {
+    lxw_workbook *workbook;
+    lxw_worksheet *worksheet;
+} excel_resource_t;
+
+zend_class_entry *vtiful_excel_ce;
+
+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()
+
+/* {{{ \Vtiful\Kernel\Excel::__construct(array $config)
+ */
+PHP_METHOD(vtiful_excel, __construct)
+{
+    zval *config;
+    zend_string *key;
+
+    ZEND_PARSE_PARAMETERS_START(1, 1)
+            Z_PARAM_ARRAY(config)
+    ZEND_PARSE_PARAMETERS_END();
+
+    key = zend_string_init(V_EXCEL_PAT, sizeof(V_EXCEL_PAT)-1, 0);
+
+    if(zend_hash_find(Z_ARRVAL_P(config), key) == NULL)
+    {
+        zend_throw_exception(vtiful_exception_ce, "Lack of 'path' configuration", 110);
+    }
+
+    zend_update_property(vtiful_excel_ce, getThis(), ZEND_STRL(V_EXCEL_COF), config);
+
+    zend_string_release(key);
+}
+/* }}} */
+
+/* {{{ \Vtiful\Kernel\Excel::filename(string $fileName)
+ */
+PHP_METHOD(vtiful_excel, fileName)
+{
+    zval rv, tmp_file_name, *config, *tmp_path, file_path;
+    zend_string *file_name, *key;
+
+    return_value = getThis();
+
+    ZEND_PARSE_PARAMETERS_START(1, 1)
+            Z_PARAM_STR(file_name)
+    ZEND_PARSE_PARAMETERS_END();
+
+    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)
+    {
+        zend_throw_exception(vtiful_exception_ce, "Configure 'path' must be a string type", 120);
+    }
+
+    ZVAL_STR(&tmp_file_name, file_name);
+    concat_function(&file_path, tmp_path, &tmp_file_name);
+
+    zend_update_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_FIL), &file_path);
+    zval_ptr_dtor(&file_path);
+}
+/* }}} */
+
+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_FE_END
+};
+
+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);
+
+    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_COF), ZEND_ACC_PRIVATE);
+
+    return SUCCESS;
+}
+
+
+

+ 12 - 0
kernel/excel.h

@@ -0,0 +1,12 @@
+#ifndef VTIFUL_EXCEL_H
+#define VTIFUL_EXCEL_H
+
+#define V_EXCEL_FIL "fileName"
+#define V_EXCEL_COF "config"
+#define V_EXCEL_PAT "path"
+
+extern zend_class_entry *vtiful_excel_ce;
+
+VTIFUL_STARTUP_FUNCTION(excel);
+
+#endif

+ 20 - 0
kernel/exception.c

@@ -0,0 +1,20 @@
+#include <php.h>
+#include "zend_exceptions.h"
+#include "php_vtiful.h"
+#include "exception.h"
+
+zend_class_entry *vtiful_exception_ce;
+
+zend_function_entry exception_methods[] = {
+        PHP_FE_END
+};
+
+VTIFUL_STARTUP_FUNCTION(vtiful_exception) {
+    zend_class_entry ce;
+
+    INIT_NS_CLASS_ENTRY(ce, "Vtiful\\Kernel", "Exception", exception_methods);
+
+    vtiful_exception_ce = zend_register_internal_class_ex(&ce, zend_ce_exception);
+
+    return SUCCESS;
+}

+ 8 - 0
kernel/exception.h

@@ -0,0 +1,8 @@
+#ifndef VTIFUL_EXCEL_EXCEPTION_H
+#define VTIFUL_EXCEL_EXCEPTION_H
+
+extern zend_class_entry *vtiful_exception_ce;
+
+VTIFUL_STARTUP_FUNCTION(vtiful_exception);
+
+#endif

+ 55 - 0
php_vtiful.h

@@ -0,0 +1,55 @@
+/*
+  +----------------------------------------------------------------------+
+  | Vtiful Extension                                                     |
+  +----------------------------------------------------------------------+
+  | Copyright (c) 2017-2017 The Viest                                    |
+  +----------------------------------------------------------------------+
+  | http://www.viest.me                                                  |
+  +----------------------------------------------------------------------+
+  | Author: viest <[email protected]>                                 |
+  +----------------------------------------------------------------------+
+*/
+
+#ifndef PHP_VTIFUL_H
+#define PHP_VTIFUL_H
+
+extern zend_module_entry vtiful_module_entry;
+#define phpext_vtiful_ptr &vtiful_module_entry
+
+#define PHP_VTIFUL_VERSION "0.1.0"
+
+#ifdef PHP_WIN32
+#	define PHP_VTIFUL_API __declspec(dllexport)
+#elif defined(__GNUC__) && __GNUC__ >= 4
+#	define PHP_VTIFUL_API __attribute__ ((visibility("default")))
+#else
+#	define PHP_VTIFUL_API
+#endif
+
+#ifdef ZTS
+#include "TSRM.h"
+#endif
+
+static 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)
+#define VTIFUL_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(vtiful, v)
+
+static void _php_vtiful_excel_close(zend_resource *rsrc TSRMLS_DC);
+
+#if defined(ZTS) && defined(COMPILE_DL_VTIFUL)
+ZEND_TSRMLS_CACHE_EXTERN();
+#endif
+
+#endif
+
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */

+ 10 - 0
tests/001.phpt

@@ -0,0 +1,10 @@
+--TEST--
+Check for vtiful presence
+--SKIPIF--
+<?php if (!extension_loaded("vtiful")) print "skip"; ?>
+--FILE--
+<?php 
+echo "vtiful extension is available";
+?>
+--EXPECT--
+vtiful extension is available

+ 152 - 0
vtiful.c

@@ -0,0 +1,152 @@
+/*
+  +----------------------------------------------------------------------+
+  | Vtiful Extension                                                     |
+  +----------------------------------------------------------------------+
+  | Copyright (c) 2017-2017 The Viest                                    |
+  +----------------------------------------------------------------------+
+  | http://www.vtiful.com                                                |
+  +----------------------------------------------------------------------+
+  | Author: viest <[email protected]>                                 |
+  +----------------------------------------------------------------------+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "php.h"
+#include "php_ini.h"
+#include "php_vtiful.h"
+#include "ext/standard/info.h"
+
+#include "kernel/excel.h"
+#include "kernel/exception.h"
+
+PHP_MINIT_FUNCTION(vtiful)
+{
+	/* If you have INI entries, uncomment these lines
+	REGISTER_INI_ENTRIES();
+	*/
+
+    VTIFUL_STARTUP_MODULE(vtiful_exception);
+	VTIFUL_STARTUP_MODULE(excel);
+
+	le_vtiful = zend_register_list_destructors_ex(_php_vtiful_excel_close, NULL, "vtiful", module_number);
+
+	return SUCCESS;
+}
+/* }}} */
+
+
+/* {{{ PHP_MSHUTDOWN_FUNCTION
+ */
+PHP_MSHUTDOWN_FUNCTION(vtiful)
+{
+	/* uncomment this line if you have INI entries
+	UNREGISTER_INI_ENTRIES();
+	*/
+	return SUCCESS;
+}
+/* }}} */
+
+
+/* Remove if there's nothing to do at request start */
+/* {{{ PHP_RINIT_FUNCTION
+ */
+PHP_RINIT_FUNCTION(vtiful)
+{
+#if defined(COMPILE_DL_VTIFUL) && defined(ZTS)
+	ZEND_TSRMLS_CACHE_UPDATE();
+#endif
+	return SUCCESS;
+}
+/* }}} */
+
+
+/* Remove if there's nothing to do at request end */
+/* {{{ PHP_RSHUTDOWN_FUNCTION
+ */
+PHP_RSHUTDOWN_FUNCTION(vtiful)
+{
+	return SUCCESS;
+}
+/* }}} */
+
+
+/* {{{ PHP_MINFO_FUNCTION
+ */
+PHP_MINFO_FUNCTION(vtiful)
+{
+	php_info_print_table_start();
+	php_info_print_table_header(2, "vtiful support", "enabled");
+	php_info_print_table_end();
+
+	/* Remove comments if you have entries in php.ini
+	DISPLAY_INI_ENTRIES();
+	*/
+}
+/* }}} */
+
+
+/* {{{ _php_fss_close
+ *
+ * List destructor for FSS handles
+ */
+static void _php_vtiful_excel_close(zend_resource *rsrc TSRMLS_DC)
+{
+//	int i;
+//	fss_resource_t * res = (fss_resource_t *)rsrc->ptr;
+//	/* Destroy the replace strings */
+//	for (i = 0; i < res->replace_size; i++) {
+//		if (res->replace[i]) {
+//			zval_ptr_dtor(res->replace[i]);
+//		}
+//	}
+//	/* Destroy the kwset structure */
+//	kwsfree(res->set);
+//	/* Destroy the resource structure itself */
+//	efree(res);
+}
+/* }}} */
+
+
+/* {{{ vtiful_functions[]
+ *
+ * Every user visible function must have an entry in vtiful_functions[].
+ */
+const zend_function_entry vtiful_functions[] = {
+	PHP_FE_END
+};
+/* }}} */
+
+/* {{{ vtiful_module_entry
+ */
+zend_module_entry vtiful_module_entry = {
+	STANDARD_MODULE_HEADER,
+	"vtiful",
+	vtiful_functions,
+	PHP_MINIT(vtiful),
+	PHP_MSHUTDOWN(vtiful),
+	PHP_RINIT(vtiful),		/* Replace with NULL if there's nothing to do at request start */
+	PHP_RSHUTDOWN(vtiful),	/* Replace with NULL if there's nothing to do at request end */
+	PHP_MINFO(vtiful),
+	PHP_VTIFUL_VERSION,
+	STANDARD_MODULE_PROPERTIES
+};
+/* }}} */
+
+#ifdef COMPILE_DL_VTIFUL
+#ifdef ZTS
+ZEND_TSRMLS_CACHE_DEFINE();
+#endif
+ZEND_GET_MODULE(vtiful)
+#endif
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */