Procházet zdrojové kódy

Feat: data reference

viest před 3 roky
rodič
revize
5546ec12a8
2 změnil soubory, kde provedl 64 přidání a 0 odebrání
  1. 4 0
      kernel/excel.c
  2. 60 0
      tests/data_reference.phpt

+ 4 - 0
kernel/excel.c

@@ -637,6 +637,10 @@ PHP_METHOD(vtiful_xls, data)
     WORKBOOK_NOT_INITIALIZED(obj);
 
     ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(data), data_r_value)
+        if (Z_TYPE_P(data_r_value) == IS_REFERENCE) {
+            data_r_value = Z_REFVAL_P(data_r_value);
+        }
+
         if(Z_TYPE_P(data_r_value) != IS_ARRAY) {
             continue;
         }

+ 60 - 0
tests/data_reference.phpt

@@ -0,0 +1,60 @@
+--TEST--
+Check for vtiful presence
+--SKIPIF--
+<?php
+require __DIR__ . '/include/skipif.inc';
+skip_disable_reader();
+?>
+--FILE--
+<?php
+$data = [
+    [23],
+    [21],
+    [21],
+    [21],
+];
+
+foreach($data as &$line) {
+    $line[0]++;
+}
+
+$excel = new \Vtiful\Kernel\Excel([
+    'path' => './tests',
+]);
+
+$fileObject = $excel->constMemory('data_reference.xlsx', NULL, false);
+$fileHandle = $fileObject->getHandle();
+
+$path = $fileObject->header(['age'])
+    ->data($data)
+    ->output();
+
+$excel->openFile('data_reference.xlsx')
+    ->openSheet();
+
+var_dump($excel->nextRow());
+var_dump($excel->nextRow());
+var_dump($excel->nextRow());
+var_dump($excel->nextRow());
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/data_reference.xlsx');
+?>
+--EXPECT--
+array(1) {
+  [0]=>
+  string(3) "age"
+}
+array(1) {
+  [0]=>
+  int(24)
+}
+array(1) {
+  [0]=>
+  int(22)
+}
+array(1) {
+  [0]=>
+  int(22)
+}