addLine($headers); } } public function addLine(array|Collection $row, array|null $sortDef = null) { if ($sortDef !== null) { $row = $this->sortColumn($sortDef, $row); } $str = ""; foreach ($row as $col => $val) { if ($str !== "") { $str .= ","; } $str .= $val; } if ($this->encode === static::ENCODE_SJIS) { $str = $this->toSjis($str); } $this->append($str); } private function toSjis(string $source): string { return mb_convert_encoding($source, "SJIS", "UTF8"); } private function sortColumn(array $sortDef, $data): array { $ele = []; $notFound = Str::uuid(); foreach ($sortDef as $def) { $ret = data_get($data, $def, $notFound); if ($ret === $notFound) { throw new LogicException("存在しない項目:" . $def); } $ele[] = $ret; } return $ele; } }