Skip to content

Commit c426d07

Browse files
authored
Merge pull request #117 from viest/dev
Feat(format): number
2 parents d4d07a9 + 03b4f54 commit c426d07

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

kernel/format.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ ZEND_END_ARG_INFO()
7070
ZEND_BEGIN_ARG_INFO_EX(format_color_arginfo, 0, 0, 1)
7171
ZEND_ARG_INFO(0, color)
7272
ZEND_END_ARG_INFO()
73+
74+
ZEND_BEGIN_ARG_INFO_EX(format_number_arginfo, 0, 0, 1)
75+
ZEND_ARG_INFO(0, format)
76+
ZEND_END_ARG_INFO()
7377
/* }}} */
7478

7579
/** {{{ \Vtiful\Kernel\Format::__construct()
@@ -179,6 +183,24 @@ PHP_METHOD(vtiful_format, color)
179183
}
180184
/* }}} */
181185

186+
/** {{{ \Vtiful\Kernel\Format::number(string $format)
187+
*/
188+
PHP_METHOD(vtiful_format, number)
189+
{
190+
zend_string *format;
191+
192+
ZEND_PARSE_PARAMETERS_START(1, 1)
193+
Z_PARAM_STR(format)
194+
ZEND_PARSE_PARAMETERS_END();
195+
196+
ZVAL_COPY(return_value, getThis());
197+
198+
format_object *obj = Z_FORMAT_P(getThis());
199+
200+
format_set_num_format(obj->ptr.format, ZSTR_VAL(format));
201+
}
202+
/* }}} */
203+
182204
/** {{{ \Vtiful\Kernel\Format::toResource()
183205
*/
184206
PHP_METHOD(vtiful_format, toResource)
@@ -199,6 +221,7 @@ zend_function_entry format_methods[] = {
199221
PHP_ME(vtiful_format, underline, format_underline_arginfo, ZEND_ACC_PUBLIC)
200222
PHP_ME(vtiful_format, align, format_align_arginfo, ZEND_ACC_PUBLIC)
201223
PHP_ME(vtiful_format, color, format_color_arginfo, ZEND_ACC_PUBLIC)
224+
PHP_ME(vtiful_format, number, format_number_arginfo, ZEND_ACC_PUBLIC)
202225
PHP_ME(vtiful_format, toResource, NULL, ZEND_ACC_PUBLIC)
203226
PHP_FE_END
204227
};

tests/format_number.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Check for vtiful presence
3+
--SKIPIF--
4+
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$config = [
8+
'path' => './tests'
9+
];
10+
11+
$fileObject = new \Vtiful\Kernel\Excel($config);
12+
13+
$fileObject = $fileObject->fileName('tutorial.xlsx');
14+
$fileHandle = $fileObject->getHandle();
15+
16+
$format = new \Vtiful\Kernel\Format($fileHandle);
17+
$numberStyle = $format->number('#,##0')->toResource();
18+
19+
$filePath = $fileObject->header(['name', 'balance'])
20+
->data([
21+
['viest', 10000],
22+
['wjx', 100000]
23+
])
24+
->setColumn('B:B', 50, $numberStyle)
25+
->output();
26+
27+
var_dump($filePath);
28+
?>
29+
--CLEAN--
30+
<?php
31+
@unlink(__DIR__ . '/tutorial.xlsx');
32+
?>
33+
--EXPECT--
34+
string(21) "./tests/tutorial.xlsx"

0 commit comments

Comments
 (0)