modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-06-14 21:36:41 +04:00
parent 8d1b10fc3c
commit 30d4c55c8a
4 changed files with 22 additions and 15 deletions

View File

@ -95,7 +95,7 @@ class PhpSpreadsheetBuilder extends AbstractBuilder {
http::content_type($contentType);
}
function _sendFile(): int {
protected function _checkOk(): bool {
switch (path::ext($this->output)) {
case ".ods":
$writer = new Ods($this->ss);
@ -105,10 +105,8 @@ class PhpSpreadsheetBuilder extends AbstractBuilder {
$writer = new Xlsx($this->ss);
break;
}
$this->rewind();
$writer->save($this->getResource());
$this->rewind();
$this->sendHeaders();
return $this->fpassthru();
return true;
}
}

View File

@ -161,10 +161,9 @@ class SpoutBuilder extends AbstractBuilder {
http::content_type($contentType);
}
function _sendFile(): int {
protected function _checkOk(): bool {
$this->ss->close();
$this->rewind();
$this->sendHeaders();
return $this->fpassthru();
return true;
}
}

View File

@ -125,11 +125,22 @@ abstract class AbstractBuilder extends TempStream implements IBuilder {
$this->sentHeaders = true;
}
abstract protected function _sendFile(): int;
function sendFile(?iterable $rows=null): int {
protected function _build(?iterable $rows=null): void {
$this->writeAll($rows);
$this->writeHeaders();
return $this->_sendFile();
}
abstract protected function _checkOk(): bool;
function build(?iterable $rows=null): bool {
$this->_build($rows);
return $this->_checkOk();
}
function sendFile(?iterable $rows=null): int {
$this->_build($rows);
if (!$this->_checkOk()) return 0;
$this->sendHeaders();
return $this->fpassthru();
}
}

View File

@ -23,11 +23,10 @@ class CsvBuilder extends AbstractBuilder {
http::content_type("text/csv");
}
protected function _sendFile(): int {
protected function _checkOk(): bool {
$size = $this->ftell();
if ($size === 0) return 0;
if ($size === 0) return false;
$this->rewind();
$this->sendHeaders();
return $this->fpassthru();
return true;
}
}