Skip to content

ExportInterface

Contract for REST file export helpers.

Implementations prepare a download response for JSON, XML, CSV, or XLSX output. Export methods return the response object so callers can continue using the normal Phalcon response pipeline.


  • Full name: \PhalconKit\Mvc\Controller\Traits\Interfaces\ExportInterface

Methods

getContentType

Resolve the requested export content type.

public getContentType(array<string,mixed>|null $params = null): string

Parameters:

Parameter Type Description
$params array|null Request/export parameters.

Return Value:

One of json, xml, csv, or xlsx.

Throws:

When the requested content type is unsupported. - HttpException


getFilename

Build the default export filename without a file extension.

public getFilename(): string

getExportColumns

Determine the union of exported columns from an array payload.

public getExportColumns(array<array-key,mixed> $list): list<string>

Parameters:

Parameter Type Description
$list array Rows to inspect.

export

Export rows using the requested or detected content type.

public export(array<array-key,mixed> $list, string|null $filename = null, string|null $contentType = null, array<array-key,mixed>|null $params = null): \Phalcon\Http\ResponseInterface

Parameters:

Parameter Type Description
$list array Rows to export.
$filename string|null Filename without extension.
$contentType string|null Explicit export type.
$params array|null Export options.

Throws:

When the content type or request-controlled export options are invalid. - HttpException When the selected exporter accepts its options but cannot generate the response payload. - RuntimeException


exportXml

Export rows as XML.

public exportXml(array<array-key,mixed> $list, string|null $filename = null, array<array-key,mixed>|null $params = null): \Phalcon\Http\ResponseInterface

Parameters:

Parameter Type Description
$list array Rows to export.
$filename string|null Filename without extension.
$params array|null XML export options.

exportJson

Export a serializable value as JSON.

public exportJson(mixed $list, string|null $filename = null, int $flags = \PhalconKit\Mvc\Controller\Traits\Interfaces\JSON_PRETTY_PRINT, int $depth = 2048): \Phalcon\Http\ResponseInterface

Parameters:

Parameter Type Description
$list mixed Serializable export payload.
$filename string|null Filename without extension.
$flags int json_encode() flags.
$depth int Maximum JSON depth.

exportExcel

Export rows as XLSX.

public exportExcel(array<array-key,mixed> $list, string|null $filename = null, bool $forceRawValue = true): \Phalcon\Http\ResponseInterface

Parameters:

Parameter Type Description
$list array Rows to export.
$filename string|null Filename without extension.
$forceRawValue bool Prefix formula-like values to reduce
spreadsheet formula injection risk.

exportCsv

Export rows as CSV.

public exportCsv(array<array-key,mixed> $list, string|null $filename = null, array<array-key,mixed>|null $params = null): \Phalcon\Http\ResponseInterface

Parameters:

Parameter Type Description
$list array Rows to export.
$filename string|null Filename without extension.
$params array|null CSV export options.

Throws:

When a CSV option has an invalid type or value. - HttpException When CSV generation fails after options have been accepted. - RuntimeException