Skip to content

Commit

Permalink
Downloader rewrite
Browse files Browse the repository at this point in the history
- Downloader knows how to fetch content from files, strings,
  X-Accel-Redirect, and functions
- List actions can return a Downloader
- List actions can return a DocumentInfo or DocumentInfoSet also
  • Loading branch information
kohler committed Sep 30, 2024
1 parent d3c1525 commit 798b659
Show file tree
Hide file tree
Showing 18 changed files with 453 additions and 217 deletions.
39 changes: 26 additions & 13 deletions lib/csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,8 @@ function set_filename($filename) {
}

/** @param bool $inline
* @return $this */
* @return $this
* @deprecated */
function set_inline($inline) {
$this->inline = $inline;
return $this;
Expand Down Expand Up @@ -1175,22 +1176,34 @@ function export_headers() {
header("X-Content-Type-Options: nosniff");
}

function emit() {
$this->flags |= self::FLAG_COMPLETING;
if (($this->flags & self::FLAG_HTTP_HEADERS) === 0) {
$this->export_headers();
/** @return bool */
function prepare_download(Downloader $dopt) {
if (($this->flags & (self::FLAG_HTTP_HEADERS | self::FLAG_COMPLETING)) !== 0
|| ($this->stream && !$this->stream_filename)) {
throw new ErrorException("Bad CsvGenerator::prepare_download");
return false;
}
$dopt = new Downloader;
$dopt->mimetype = $this->mimetype_with_charset();
$this->flags |= self::FLAG_COMPLETING;
$dopt->set_mimetype($this->mimetype_with_charset())
->set_filename($this->filename());
if ($this->stream) {
$this->flush();
if ($this->stream_filename) {
$dopt->output_file($this->stream_filename);
} else {
assert(($this->flags & self::FLAG_EMIT_LIVE) !== 0);
}
$dopt->set_content_file($this->stream_filename);
} else {
$dopt->set_content($this->unparse());
}
return true;
}

function emit() {
if ($this->stream && !$this->stream_filename) {
// emitted as we went along
assert(($this->flags & self::FLAG_EMIT_LIVE) !== 0);
$this->flush();
} else {
$dopt->output_string($this->unparse());
$dopt = new Downloader;
$this->prepare_download($dopt);
$dopt->emit();
}
}
}
Loading

0 comments on commit 798b659

Please sign in to comment.