| Server IP : 35.236.43.222 / Your IP : 216.73.216.143 Web Server : Apache System : Linux order-form-vm-001 5.10.0-37-cloud-amd64 #1 SMP Debian 5.10.247-1 (2025-12-11) x86_64 User : deploy ( 1002) PHP Version : 8.1.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/ravel.network/public/wp-content/plugins/independent-analytics/IAWP/Utils/ |
Upload File : |
<?php
namespace IAWP\Utils;
use IAWPSCOPED\League\Csv\EscapeFormula;
/** @internal */
class CSV
{
private array $header;
private array $rows;
private EscapeFormula $formatter;
/**
* @param array $header
* @param array[] $rows
*/
public function __construct(array $header, array $rows)
{
$this->header = $header;
$this->rows = $rows;
$this->formatter = new EscapeFormula();
}
public function to_string() : string
{
$delimiter = ',';
$enclosure = '"';
$escape_character = '\\';
$temporary_file = \fopen('php://memory', 'r+');
\fputcsv($temporary_file, $this->header, $delimiter, $enclosure, $escape_character);
foreach ($this->rows as $row) {
$row = $this->escape_row($row);
\fputcsv($temporary_file, $row, $delimiter, $enclosure, $escape_character);
}
\rewind($temporary_file);
return \stream_get_contents($temporary_file);
}
private function escape_row(array $row) : array
{
$row = $this->formatter->escapeRecord($row);
foreach ($row as &$cell) {
if ($cell === "'-") {
$cell = '-';
}
}
return $row;
}
}