Browse Source

Feat(format): number

viest 6 years ago
parent
commit
03b4f54d93
2 changed files with 57 additions and 0 deletions
  1. 23 0
      kernel/format.c
  2. 34 0
      tests/format_number.phpt

+ 23 - 0
kernel/format.c

@@ -70,6 +70,10 @@ ZEND_END_ARG_INFO()
 ZEND_BEGIN_ARG_INFO_EX(format_color_arginfo, 0, 0, 1)
                 ZEND_ARG_INFO(0, color)
 ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(format_number_arginfo, 0, 0, 1)
+                ZEND_ARG_INFO(0, format)
+ZEND_END_ARG_INFO()
 /* }}} */
 
 /** {{{ \Vtiful\Kernel\Format::__construct()
@@ -179,6 +183,24 @@ PHP_METHOD(vtiful_format, color)
 }
 /* }}} */
 
+/** {{{ \Vtiful\Kernel\Format::number(string $format)
+ */
+PHP_METHOD(vtiful_format, number)
+{
+    zend_string *format;
+
+    ZEND_PARSE_PARAMETERS_START(1, 1)
+            Z_PARAM_STR(format)
+    ZEND_PARSE_PARAMETERS_END();
+
+    ZVAL_COPY(return_value, getThis());
+
+    format_object *obj = Z_FORMAT_P(getThis());
+
+    format_set_num_format(obj->ptr.format, ZSTR_VAL(format));
+}
+/* }}} */
+
 /** {{{ \Vtiful\Kernel\Format::toResource()
  */
 PHP_METHOD(vtiful_format, toResource)
@@ -199,6 +221,7 @@ zend_function_entry format_methods[] = {
         PHP_ME(vtiful_format, underline,   format_underline_arginfo, ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_format, align,       format_align_arginfo,     ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_format, color,       format_color_arginfo,     ZEND_ACC_PUBLIC)
+        PHP_ME(vtiful_format, number,      format_number_arginfo,    ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_format, toResource,  NULL,                     ZEND_ACC_PUBLIC)
         PHP_FE_END
 };

+ 34 - 0
tests/format_number.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);
+$numberStyle = $format->number('#,##0')->toResource();
+
+$filePath = $fileObject->header(['name', 'balance'])
+    ->data([
+        ['viest', 10000],
+        ['wjx',   100000]
+    ])
+    ->setColumn('B:B', 50, $numberStyle)
+    ->output();
+
+var_dump($filePath);
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/tutorial.xlsx');
+?>
+--EXPECT--
+string(21) "./tests/tutorial.xlsx"