ExportResult
API reference › CSV Export › ExportResult
Owns the private workspace and delivers the files produced by an export.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$archiver | callable(list<string>, | Alternative archiver receiving the finalized CSV paths and workspace path. Default: null. | ExportResult |
$basePath | string | Parent directory or Yii alias for private export workspaces. Default: '@runtime/csv-export'. | ExportResult |
$csvFiles | list<CsvFile> | Writers registered with this result, in export order. Default: []. | ExportResult |
$dirName | string | The private directory. | ExportResult |
$fileBaseName | string | Base name used for the numbered CSV files and the default ZIP archive. Default: 'data'. | ExportResult |
$forceArchive | bool | Archives even a single CSV when enabled. Default: false. | ExportResult |
$resultFileName read-only | string| | The finalized result path. | ExportResult |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Constructor. | yii\ |
__call() | Calls the named method which is not a class method. | yii\ |
__destruct() | Attempts to release the workspace without reporting cleanup errors. | ExportResult |
__get() | Returns the value of an object property. | yii\ |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\ |
__set() | Sets value of an object property. | yii\ |
__unset() | Sets an object property to null. | yii\ |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\ |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\ |
className() static | Returns the fully qualified name of this class. | yii\ |
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\ |
hasProperty() | Returns a value indicating whether a property is defined. | yii\ |
init() | Initializes the object. | yii\ |
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() static | Removes 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() protected | Archives finalized CSV files with the configured archiver or the built-in ZIP writer. | ExportResult |
createZipArchive() protected | Creates an unopened archive writer for the built-in archiver. | ExportResult |
prepareDestinationFileName() protected | Resolves the destination alias and creates its parent directory when needed. | ExportResult |
Property details
Section titled “Property details”$archiver
Section titled “$archiver ”public callable(list<string>, string): string|null $archiver = nullAlternative archiver receiving the finalized CSV paths and workspace path.
Return the path of a separate, readable archive directly inside that workspace.
$dirName
Section titled “$dirName ”public string $dirNameThe private directory.
Setting this property configures its parent.
Method details
Section titled “Method details”__destruct()
Section titled “__destruct() ”public function __destruct(): mixedAttempts to release the workspace without reporting cleanup errors.
Returns
mixed
copy()
Section titled “copy() ”public function copy(string $destinationFileName): boolPublishes the result outside the workspace and retains the temporary files.
Parameters
| Parameter | Type | Description |
|---|---|---|
$destinationFileName | string | Destination path or Yii alias. |
Returns
bool: Whether a result was published.
Throws
yii\base\InvalidConfigException: if the destination is inside the private workspace.yii\base\Exception: if the result, destination directory or temporary delivery file cannot be prepared.
delete()
Section titled “delete() ”public function delete(): boolFinalizes 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
yii\base\Exception: if finalizing a writer or cleaning up fails.
getDirName()
Section titled “getDirName() ”public function getDirName(): stringCreates and locks the private workspace on first access.
Returns
string: The absolute workspace path.
Throws
yii\base\Exception: if the workspace or its lock cannot be prepared.
getResultFileName()
Section titled “getResultFileName() ”public function getResultFileName(): string|nullReturns the finalized CSV or archive, creating the archive if needed.
Returns
string|null: Absolute result path, or null if no writers were registered.
Throws
yii\base\Exception: if an input is incomplete, unreadable or outside the workspace, or archiving fails.yii\base\InvalidConfigException: if the default archiver is needed but the ZIP extension is unavailable.
move()
Section titled “move() ”public function move(string $destinationFileName): boolPublishes the result outside the workspace and cleans up after a successful copy.
newCsvFile()
Section titled “newCsvFile() ”public function newCsvFile(array<string, mixed> $config = []): yii2\extensions\csvexport\CsvFileRegisters a writer with a numbered CSV path in the private workspace without opening it.
Parameters
| Parameter | Type | Description |
|---|---|---|
$config | array<string, | Writer options, optionally including a subclass in class. |
Returns
CsvFile: The registered, unopened writer.
Throws
yii\base\InvalidConfigException: if the writer class or file base name is invalid.yii\base\Exception: if the workspace or its lock cannot be prepared.
purgeExpired()
Section titled “purgeExpired() ”public static function purgeExpired(string $basePath, int $ageInSeconds): intRemoves unlocked workspaces whose lease file is older than the retention period.
Parameters
| Parameter | Type | Description |
|---|---|---|
$basePath | string | Trusted parent directory or Yii alias. |
$ageInSeconds | int | Positive retention period in seconds. |
Returns
int: The number of workspaces removed.
Throws
yii\base\InvalidConfigException: if the retention period is not positive.yii\base\Exception: if the parent directory cannot be read.
saveAs()
Section titled “saveAs() ”public function saveAs(string $file, bool $deleteTempFile = true): boolPublishes the result, removing temporary files by default.
send()
Section titled “send() ”public function send(string|null $name = null, array<string, mixed> $options = []): yii\web\ResponsePrepares a web download and schedules workspace cleanup after the response is sent.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string| | Download name without directories, or null to use the result file name. |
$options | array<string, | Options passed to the response’s file sender. |
Returns
yii\web\Response: The application response, prepared to send the file.
Throws
yii\base\InvalidConfigException: if no Yii web application is active or the download name is invalid.LogicException: if there is no finalized result to send.
setDirName()
Section titled “setDirName() ”public function setDirName(string $directory): voidSets the parent directory before the workspace is created.
Parameters
| Parameter | Type | Description |
|---|---|---|
$directory | string | Parent directory or Yii alias. |
Throws
LogicException: if the workspace already exists.
archiveFiles()
Section titled “archiveFiles() ”protected function archiveFiles(list<string> $files): stringArchives finalized CSV files with the configured archiver or the built-in ZIP writer.
Parameters
| Parameter | Type | Description |
|---|---|---|
$files | list<string> | The absolute paths of the finalized CSV files. |
Returns
string: The archive path.
Throws
yii\base\InvalidConfigException: if the built-in ZIP writer is selected and the ZIP extension is missing.yii\base\Exception: if creating or publishing the archive fails.
createZipArchive()
Section titled “createZipArchive() ”protected function createZipArchive(): ZipArchiveCreates an unopened archive writer for the built-in archiver.
Returns
ZipArchive: The archive writer.
prepareDestinationFileName()
Section titled “prepareDestinationFileName() ”protected function prepareDestinationFileName(string $destinationFileName): stringResolves the destination alias and creates its parent directory when needed.
Parameters
| Parameter | Type | Description |
|---|---|---|
$destinationFileName | string | Destination path or Yii alias. |
Returns
string: The absolute destination path, with its parent directory resolved.
Throws
yii\base\Exception: if the destination directory cannot be prepared.