Write a row to the file.

@param array $row The row to write.

@return int The length of the line written.
@throws \RuntimeException On error.
7527
public function write(array $row)
    {

        // Open the file if it's not already open.
        if ($this->csv === null) {
            $csv = fopen($this->getConfig('file'), 'w');
            if (is_resource($csv) === false) {
                throw new \RuntimeException('Unable to open output file.');
            }
            $this->csv = $csv;
        }

        // If we're not using a header row, just output the values.
        // The caller will have to ensure the proper column order.
        if ($this->getConfig('header') === false) {
            return $this->put(array_values($row));
        }

        // Output the header row if we haven't already.
        if ($this->columns === null) {
            $this->columns = $this->getConfig('columns') === null ? array_keys($row) : $this->getConfig('columns');
            $this->put($this->columns);
        }

        // If this data row doesn't contain values for all the fields in the
        // header row, then insert empty values for the missing fields, so
        // that the CSV columns line up properly. Also, make sure that the
        // columns are in the order that was specified in the header row.
        $ordered = [];
        foreach ($this->columns as $column) {
            $ordered[] = array_key_exists($column, $row) === true ? $row[$column] : '';
        }
        return $this->put($ordered);

    }
448781
private function writeNumber($number)
    {
        // Truncate
        if (!ftruncate($this->handle, 0)) {
            throw new RuntimeException("Failed to truncate file {$this->path}.");
        }
        // Reset
        if (0 > fseek($this->handle, 0)) {
            throw new RuntimeException("Failed to move pointer at the beginning of the file {$this->path}.");
        }
        // Write
        if (!fwrite($this->handle, $number)) {
            throw new RuntimeException("Failed to write file {$this->path}.");
        }
        // Flush
        if (!fflush($this->handle)) {
            throw new RuntimeException("Failed to flush file {$this->path}.");
        }
        // Unlock
        if (!flock($this->handle, LOCK_UN)) {
            throw new RuntimeException("Failed to unlock file {$this->path}.");
        }
        // Close
        fclose($this->handle);
    }
1167512
public function insertRow($row): void {
        if ($this->connection === null) {
            throw new \RuntimeException('Copying already ended. Create a new object');
        }
        if (is_array($row)) {
            $row = $this->escape($row);
        }
        $wynik = @pg_put_line($this->connection, $row);
        if ($wynik === false) {
            throw new \RuntimeException('Failed to insert the row');
        }
    }
74259
private function log( $row ){
		$path_logfile = $this->path_tmp_publish.'publish_log.csv';
		if( !is_file( $path_logfile ) ){
			error_log( $this->px->fs()->mk_csv( array(array(
				'datetime' ,
				'path' ,
				'proc_type' ,
				'status_code' ,
				'status_message' ,
				'errors' ,
				'filesize',
				'user_agent',
				'proc_microtime'
			)) ), 3, $path_logfile );
			clearstatcache();
		}
		return error_log( $this->px->fs()->mk_csv( array($row) ), 3, $path_logfile );
	}
223215
private function buildFile($row)
    {
        $file = new File(
            new FileId($row['id']),
            new FileName($row['name'] . '.' . $row['extension']),
            new FileMimeType($row['mime_type'])
        );

        $createdOn = new \DateTimeImmutable($row['created_on']);
        $updatedOn = new \DateTimeImmutable($row['updated_on']);

        $file = $this->set($file, 'createdOn', $createdOn);
        $file = $this->set($file, 'updatedOn', $updatedOn);

        return $file;
    }
99545
public function insert(array $row): ?int
    {
        // 这两个字段是表必备字段,并自动更新
        $row = array_filter(self::appendAutoField($row));

        // 执行前置钩子
        $ret = $this->before('Insert', 'Insert', $row);
        if ($ret === self::INTERRUPT) {
            return null;
        }
        $row = array_pop($ret);

        //Insert/Replace/InsertIgnore的后继处理
        return self::afterInsertReplaceInsertIgnore('Insert', $row);
    }
479479
public function process(array $row)
    {
        foreach ($row as &$item) {
            if (is_object($item)) {
                if (method_exists($item, '__toString')) {
                    $item = $item->__toString();
                } else {
                    throw new InvalidArgumentException("Supplied object does not implement __toString");
                }
            }
        }

        return $row;
    }
834927
public function writeRow(iterable $row): void
    {
        // Convert to bag here in case $row cannot be rewound
        $row = Bag::from($row);

        if ($row->isIndexed()) {
            $this->writer->writeRow($row);

            return;
        }

        // If headers have not been set, use the keys of the given row
        if ($this->headers === null) {
            $this->headers = $row->keys();
        }

        $extra = $row->omit(...$this->headers);
        if (!$extra->isEmpty()) {
            throw new \RuntimeException(
                sprintf('Row contains extra fields not found in headers: "%s"', $extra->keys()->join('", "'))
            );
        }

        // Correctly sort values based on headers
        $row = $this->headers
            ->flip()
            ->replace($row)
            ->values()
        ;

        $this->writer->writeRow($row);
    }
350866
public function addRow(array $row, Style $style)
    {
        $columnCount = count($row);
        $this->updateMaxColumnCount($columnCount);
        $cellXml = $this->getCellXml($row, $style);

        return $this->getRowXml($columnCount, $cellXml);
    }
103735
public function setFromArray(array $row = [])
    {
        parent::setFromArray($row);
        try {
            $data = $this->data ? json_decode($this->data, true) : [];
        } catch (\Exception $e) {
            $data = [];
        }
        $this->data = (new DataObject)->setParams($data);
        return $this;
    }
260454
protected function _write($data)
    {
        if (!$this->connected) {
            $message = 'No connecting found while writing data to socket.';
            throw new RuntimeException($message);
        }

        $data .= "\r\n";

        $length = strlen($data);
        $fwrited = fwrite($this->_connection, $data, $length);

        if ($fwrited === false) {
            throw new SocketException('Socket is broken, write failed: '.substr($data, 0, 100));
        } elseif ($fwrited < $length) {
            throw new SocketException("Socket is broken, only write {$fwrited} bytes of {$length} bytes: ".substr($data, 0, 100));
        }

        return $fwrited;
    }
983658
public function write($string): int
    {
        if (!$this->isWritable()) {
            throw new RuntimeException;
        }
        if (fwrite($this->stream, $string) === false) {
            throw new RuntimeException;
        }
        return \mb_strlen($string);
    }
745376
private function getCellWidth(array $row, $column) {
        $cellWidth = 0;

        if (isset($row[$column])) {
            $cell = $row[$column];
            $cellWidth = Console::strlenWithoutDecoration($this->output->getFormatter(), $cell);
        }

        $columnWidth = isset($this->columnWidths[$column]) ? $this->columnWidths[$column] : 0;

        return max($cellWidth, $columnWidth);
    }
958796
public function appendRow($row): self
    {
        if (!$this->output instanceof ConsoleSectionOutput) {
            throw new RuntimeException(sprintf('Output should be an instance of "%s" when calling "%s".', ConsoleSectionOutput::class, __METHOD__));
        }

        if ($this->rendered) {
            $this->output->clear($this->calculateRowCount());
        }

        $this->addRow($row);
        $this->render();

        return $this;
    }
933848
public function addRow($row)
    {
        if ($row instanceof TableSeparator) {
            $this->rowsCopy[] = $row;

            return parent::addRow($row);
        }

        if (!is_array($row)) {
            throw new \InvalidArgumentException('A row must be an array or a TableSeparator instance.');
        }

        $this->rowsCopy[] = array_values($row);

        return parent::addRow($row);
    }
223882
private function getNumberOfColumns(array $row)
    {
        $columns = count($row);
        foreach ($row as $column) {
            $columns += $column instanceof TableCell ? ($column->getColspan() - 1) : 0;
        }

        return $columns;
    }
1269951
protected function serializeFields(array $row)
    {
        $data    = array();
        $columns = $this->getColumns();

        $builder = $this->newQueryBuilder($this->getName());
        $parts   = $builder->getQueryPart('from');
        $part    = reset($parts);
        $alias   = $part['alias'];

        foreach ($columns as $name => $type) {
            if (!empty($alias)) {
                $pos = strpos($name, $alias . '.');
                if ($pos !== false) {
                    $name = substr($name, strlen($alias) + 1);
                }
            }

            if (isset($row[$name])) {
                $data[$name] = $this->serializeType($row[$name], $type);
            }
        }

        return $data;
    }