Version 1
[yaffs-website] / vendor / consolidation / output-formatters / src / Formatters / RenderTableDataTrait.php
diff --git a/vendor/consolidation/output-formatters/src/Formatters/RenderTableDataTrait.php b/vendor/consolidation/output-formatters/src/Formatters/RenderTableDataTrait.php
new file mode 100644 (file)
index 0000000..32fa71b
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+namespace Consolidation\OutputFormatters\Formatters;
+
+use Consolidation\OutputFormatters\Options\FormatterOptions;
+use Consolidation\OutputFormatters\StructuredData\RenderCellInterface;
+
+trait RenderTableDataTrait
+{
+    /**
+     * @inheritdoc
+     */
+    public function renderData($originalData, $restructuredData, FormatterOptions $options)
+    {
+        if ($originalData instanceof RenderCellInterface) {
+            return $this->renderEachCell($originalData, $restructuredData, $options);
+        }
+        return $restructuredData;
+    }
+
+    protected function renderEachCell($originalData, $restructuredData, FormatterOptions $options)
+    {
+        foreach ($restructuredData as $id => $row) {
+            foreach ($row as $key => $cellData) {
+                $restructuredData[$id][$key] = $originalData->renderCell($key, $cellData, $options, $row);
+            }
+        }
+        return $restructuredData;
+    }
+}