瀏覽代碼

Refactor: background parameter adjustment

viest 5 年之前
父節點
當前提交
37520b3263
共有 2 個文件被更改,包括 9 次插入8 次删除
  1. 7 6
      kernel/format.c
  2. 2 2
      tests/format_background.phpt

+ 7 - 6
kernel/format.c

@@ -229,15 +229,16 @@ PHP_METHOD(vtiful_format, number)
 }
 /* }}} */
 
-/** {{{ \Vtiful\Kernel\Format::background(int $pattern, int $color)
+/** {{{ \Vtiful\Kernel\Format::background(int $color [, int $pattern = \Vtiful\Kernel\Format::PATTERN_SOLID])
  */
 PHP_METHOD(vtiful_format, background)
 {
-    zend_long pattern = 0, color = 0;
+    zend_long pattern = LXW_PATTERN_SOLID, color = 0;
 
-    ZEND_PARSE_PARAMETERS_START(2, 2)
-            Z_PARAM_LONG(pattern)
+    ZEND_PARSE_PARAMETERS_START(1, 2)
             Z_PARAM_LONG(color)
+            Z_PARAM_OPTIONAL
+            Z_PARAM_LONG(pattern)
     ZEND_PARSE_PARAMETERS_END();
 
     ZVAL_COPY(return_value, getThis());
@@ -245,8 +246,8 @@ PHP_METHOD(vtiful_format, background)
     format_object *obj = Z_FORMAT_P(getThis());
 
     if (obj->ptr.format) {
-        format_set_pattern(obj->ptr.format, (uint8_t)pattern);
-        format_set_bg_color(obj->ptr.format, (uint8_t)color);
+        format_set_pattern(obj->ptr.format, pattern);
+        format_set_bg_color(obj->ptr.format, color);
     }
 }
 /* }}} */

+ 2 - 2
tests/format_background.phpt

@@ -15,8 +15,8 @@ $fileHandle = $fileObject->getHandle();
 
 $format = new \Vtiful\Kernel\Format($fileHandle);
 $style  = $format->background(
-	\Vtiful\Kernel\Format::PATTERN_LIGHT_UP,
-	\Vtiful\Kernel\Format::COLOR_RED
+	\Vtiful\Kernel\Format::COLOR_RED,
+	\Vtiful\Kernel\Format::PATTERN_LIGHT_UP
 )->toResource();
 
 $filePath = $fileObject->header(['name', 'age'])