浏览代码

Feat: unlock format

viest 4 年之前
父节点
当前提交
da3ba2bf1d
共有 2 个文件被更改,包括 52 次插入0 次删除
  1. 18 0
      kernel/format.c
  2. 34 0
      tests/format_unlocked.phpt

+ 18 - 0
kernel/format.c

@@ -72,6 +72,9 @@ ZEND_BEGIN_ARG_INFO_EX(format_underline_arginfo, 0, 0, 1)
                 ZEND_ARG_INFO(0, style)
                 ZEND_ARG_INFO(0, style)
 ZEND_END_ARG_INFO()
 ZEND_END_ARG_INFO()
 
 
+ZEND_BEGIN_ARG_INFO_EX(format_unlocked_arginfo, 0, 0, 0)
+ZEND_END_ARG_INFO()
+
 ZEND_BEGIN_ARG_INFO_EX(format_align_arginfo, 0, 0, 1)
 ZEND_BEGIN_ARG_INFO_EX(format_align_arginfo, 0, 0, 1)
                 ZEND_ARG_VARIADIC_INFO(0, style)
                 ZEND_ARG_VARIADIC_INFO(0, style)
 ZEND_END_ARG_INFO()
 ZEND_END_ARG_INFO()
@@ -179,6 +182,20 @@ PHP_METHOD(vtiful_format, underline)
 }
 }
 /* }}} */
 /* }}} */
 
 
+/** {{{ \Vtiful\Kernel\Format::unlocked()
+ */
+PHP_METHOD(vtiful_format, unlocked)
+{
+    ZVAL_COPY(return_value, getThis());
+
+    format_object *obj = Z_FORMAT_P(getThis());
+
+    if (obj->ptr.format) {
+        format_set_unlocked(obj->ptr.format);
+    }
+}
+/* }}} */
+
 /** {{{ \Vtiful\Kernel\Format::align()
 /** {{{ \Vtiful\Kernel\Format::align()
  */
  */
 PHP_METHOD(vtiful_format, align)
 PHP_METHOD(vtiful_format, align)
@@ -385,6 +402,7 @@ zend_function_entry format_methods[] = {
         PHP_ME(vtiful_format, fontSize,      format_size_arginfo,        ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_format, fontSize,      format_size_arginfo,        ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_format, strikeout,     format_strikeout_arginfo,   ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_format, strikeout,     format_strikeout_arginfo,   ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_format, underline,     format_underline_arginfo,   ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_format, underline,     format_underline_arginfo,   ZEND_ACC_PUBLIC)
+        PHP_ME(vtiful_format, unlocked,      format_unlocked_arginfo,    ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_format, toResource,    format_to_resource_arginfo, ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_format, toResource,    format_to_resource_arginfo, ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_format, background,    format_background_arginfo,  ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_format, background,    format_background_arginfo,  ZEND_ACC_PUBLIC)
         PHP_FE_END
         PHP_FE_END

+ 34 - 0
tests/format_unlocked.phpt

@@ -0,0 +1,34 @@
+--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');
+$fileHandle = $fileObject->getHandle();
+
+$format       = new \Vtiful\Kernel\Format($fileHandle);
+$unlockedStyle = $format->unlocked()->toResource();
+
+$filePath = $fileObject->header(['name', 'age'])
+    ->data([
+        ['wjx',   21]
+    ])
+    ->setRow('A2', 50, $unlockedStyle)
+    ->protection()
+    ->output();
+
+var_dump($filePath);
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/tutorial.xlsx');
+?>
+--EXPECT--
+string(21) "./tests/tutorial.xlsx"