Skip to content
PHP Ecosystem
Explore

CsvFile

API reference › CSV Export › CsvFile

classyii2\extensions\csvexport\CsvFile
Extendsyii\base\BaseObject
Implementsyii\base\Configurable
Sourcesrc/CsvFile.php

CsvFile represents the CSV file.

PropertyTypeDescriptionDefined by
$cellDelimiterstringDelimiter between the CSV file cells. Default: ','.CsvFile
$enclosurestringThe cell content enclosure. Default: '"'.CsvFile
$encodingstringOutput encoding. Input text for UTF-16 export must be UTF-8. Default: 'UTF-8'.CsvFile
$entriesCountintThe count of entries written into the file. Default: 0.CsvFile
$namestringThe path of the file. A standalone CSV survives destruction. Default: ''.CsvFile
$rowDelimiterstringDelimiter between the CSV file rows. Default: "\r\n".CsvFile
$spreadsheetSafeboolPrefixes formula-like text with an apostrophe for spreadsheet import. Default: false.CsvFile
$writeBombool|string|nullWrites the encoding’s BOM when enabled, or a supplied literal prefix. Default: false.CsvFile
$fileHandler protectedresource|nullStream for the active write, or null when no stream is open. Default: null.CsvFile
MethodDescriptionDefined by
__construct()Constructor.yii\base\BaseObject
__call()Calls the named method which is not a class method.yii\base\BaseObject
__destruct()Attempts to finalize an open stream without reporting I/O errors.CsvFile
__get()Returns the value of an object property.yii\base\BaseObject
__isset()Checks if a property is set, i.e. defined and not null.yii\base\BaseObject
__set()Sets value of an object property.yii\base\BaseObject
__unset()Sets an object property to null.yii\base\BaseObject
canGetProperty()Returns a value indicating whether a property can be read.yii\base\BaseObject
canSetProperty()Returns a value indicating whether a property can be set.yii\base\BaseObject
className() staticReturns the fully qualified name of this class.yii\base\BaseObject
close()Finalizes an open CSV and checks that buffered bytes were flushed.CsvFile
delete()Removes the named file and ends the writer’s lifecycle.CsvFile
hasMethod()Returns a value indicating whether a method is defined.yii\base\BaseObject
hasProperty()Returns a value indicating whether a property is defined.yii\base\BaseObject
init()Initializes the object.yii\base\BaseObject
isComplete()Indicates that the finalized file can be included in a result.CsvFile
open()Opens the CSV for writing and allows retry after a failed open.CsvFile
writeRow()Writes a complete CSV record.CsvFile
composeRowContent() protectedEncodes the cells and prepends a record separator after the first row.CsvFile
encodeValue() protectedConverts supported cell types and applies the selected dialect.CsvFile
writeContent() protectedWrites the given content into the file.CsvFile
public function __destruct(): mixed

Attempts to finalize an open stream without reporting I/O errors.

Returns

mixed

public function close(): bool

Finalizes an open CSV and checks that buffered bytes were flushed.

Returns

bool: Always true.

Throws

public function delete(): bool

Removes the named file and ends the writer’s lifecycle.

Returns

bool: Whether the file is absent after the call.

Throws

public function isComplete(): bool

Indicates that the finalized file can be included in a result.

Returns

bool: Whether the file was closed without a failure and is readable.

public function open(): bool

Opens the CSV for writing and allows retry after a failed open.

Returns

bool: Always true.

Throws

public function writeRow(array<array-key, mixed>|object $rowData): int

Writes a complete CSV record.

Parameters

ParameterTypeDescription
$rowDataarray<array-key, mixed>|objectCell values: an array, a Traversable or public properties.

Returns

int: The byte count of the record, without the BOM.

Throws

protected function composeRowContent(array<array-key, mixed>|object $rowData): string

Encodes the cells and prepends a record separator after the first row.

Parameters

ParameterTypeDescription
$rowDataarray<array-key, mixed>|objectCell values: an array, a Traversable or public properties.

Returns

string: The encoded record.

Throws

protected function encodeValue(mixed $value): string

Converts supported cell types and applies the selected dialect.

Parameters

ParameterTypeDescription
$valuemixedScalar, null or Stringable cell value.

Returns

string: The cell text, enclosed and escaped when an enclosure is set. An unquoted cell contains a delimiter or line break.

Throws

protected function writeContent(string $content): int

Writes the given content into the file.

Parameters

ParameterTypeDescription
$contentstringContent to be written.

Returns

int: The number of bytes written.

Throws