Skip to content
PHP Ecosystem
Explore

ExportResult

API reference › CSV Export › ExportResult

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

Owns the private workspace and delivers the files produced by an export.

PropertyTypeDescriptionDefined by
$archivercallable(list<string>, string): string|nullAlternative archiver receiving the finalized CSV paths and workspace path. Default: null.ExportResult
$basePathstringParent directory or Yii alias for private export workspaces. Default: '@runtime/csv-export'.ExportResult
$csvFileslist<CsvFile>Writers registered with this result, in export order. Default: [].ExportResult
$dirNamestringThe private directory.ExportResult
$fileBaseNamestringBase name used for the numbered CSV files and the default ZIP archive. Default: 'data'.ExportResult
$forceArchiveboolArchives even a single CSV when enabled. Default: false.ExportResult
$resultFileName read-onlystring|nullThe finalized result path.ExportResult
MethodDescriptionDefined by
__construct()Constructor.yii\base\BaseObject
__call()Calls the named method which is not a class method.yii\base\BaseObject
__destruct()Attempts to release the workspace without reporting cleanup errors.ExportResult
__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
copy()Publishes the result outside the workspace and retains the temporary files.ExportResult
delete()Finalizes registered writers, removes the owned workspace and releases its lock.ExportResult
getDirName()Creates and locks the private workspace on first access.ExportResult
getResultFileName()Returns the finalized CSV or archive, creating the archive if needed.ExportResult
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
move()Publishes the result outside the workspace and cleans up after a successful copy.ExportResult
newCsvFile()Registers a writer with a numbered CSV path in the private workspace without opening it.ExportResult
purgeExpired() staticRemoves unlocked workspaces whose lease file is older than the retention period.ExportResult
saveAs()Publishes the result, removing temporary files by default.ExportResult
send()Prepares a web download and schedules workspace cleanup after the response is sent.ExportResult
setDirName()Sets the parent directory before the workspace is created.ExportResult
archiveFiles() protectedArchives finalized CSV files with the configured archiver or the built-in ZIP writer.ExportResult
createZipArchive() protectedCreates an unopened archive writer for the built-in archiver.ExportResult
prepareDestinationFileName() protectedResolves the destination alias and creates its parent directory when needed.ExportResult
public callable(list<string>, string): string|null $archiver = null

Alternative archiver receiving the finalized CSV paths and workspace path.

Return the path of a separate, readable archive directly inside that workspace.

public string $dirName

The private directory.

Setting this property configures its parent.

public function __destruct(): mixed

Attempts to release the workspace without reporting cleanup errors.

Returns

mixed

public function copy(string $destinationFileName): bool

Publishes the result outside the workspace and retains the temporary files.

Parameters

ParameterTypeDescription
$destinationFileNamestringDestination path or Yii alias.

Returns

bool: Whether a result was published.

Throws

public function delete(): bool

Finalizes registered writers, removes the owned workspace and releases its lock.

Every writer is closed even when an earlier one fails. The first finalizing failure is rethrown after cleanup, unless cleanup itself fails.

Returns

bool: Whether a workspace had been allocated.

Throws

public function getDirName(): string

Creates and locks the private workspace on first access.

Returns

string: The absolute workspace path.

Throws

public function getResultFileName(): string|null

Returns the finalized CSV or archive, creating the archive if needed.

Returns

string|null: Absolute result path, or null if no writers were registered.

Throws

public function move(string $destinationFileName): bool

Publishes the result outside the workspace and cleans up after a successful copy.

Parameters

ParameterTypeDescription
$destinationFileNamestringDestination path or Yii alias.

Returns

bool: Whether a result was published.

See also

public function newCsvFile(array<string, mixed> $config = []): yii2\extensions\csvexport\CsvFile

Registers a writer with a numbered CSV path in the private workspace without opening it.

Parameters

ParameterTypeDescription
$configarray<string, mixed>Writer options, optionally including a subclass in class.

Returns

CsvFile: The registered, unopened writer.

Throws

public static function purgeExpired(string $basePath, int $ageInSeconds): int

Removes unlocked workspaces whose lease file is older than the retention period.

Parameters

ParameterTypeDescription
$basePathstringTrusted parent directory or Yii alias.
$ageInSecondsintPositive retention period in seconds.

Returns

int: The number of workspaces removed.

Throws

public function saveAs(string $file, bool $deleteTempFile = true): bool

Publishes the result, removing temporary files by default.

Parameters

ParameterTypeDescription
$filestringDestination path or Yii alias.
$deleteTempFileboolWhether to clean up after a successful copy.

Returns

bool: Whether a result was published.

See also

public function send(string|null $name = null, array<string, mixed> $options = []): yii\web\Response

Prepares a web download and schedules workspace cleanup after the response is sent.

Parameters

ParameterTypeDescription
$namestring|nullDownload name without directories, or null to use the result file name.
$optionsarray<string, mixed>Options passed to the response’s file sender.

Returns

yii\web\Response: The application response, prepared to send the file.

Throws

public function setDirName(string $directory): void

Sets the parent directory before the workspace is created.

Parameters

ParameterTypeDescription
$directorystringParent directory or Yii alias.

Throws

protected function archiveFiles(list<string> $files): string

Archives finalized CSV files with the configured archiver or the built-in ZIP writer.

Parameters

ParameterTypeDescription
$fileslist<string>The absolute paths of the finalized CSV files.

Returns

string: The archive path.

Throws

protected function createZipArchive(): ZipArchive

Creates an unopened archive writer for the built-in archiver.

Returns

ZipArchive: The archive writer.

protected function prepareDestinationFileName(string $destinationFileName): string

Resolves the destination alias and creates its parent directory when needed.

Parameters

ParameterTypeDescription
$destinationFileNamestringDestination path or Yii alias.

Returns

string: The absolute destination path, with its parent directory resolved.

Throws