Skip to content

Commit

Permalink
Merge pull request #4 from andrea-daru/streamed-response
Browse files Browse the repository at this point in the history
Streamed response
  • Loading branch information
andrea-daru authored Mar 22, 2018
2 parents a1d9a1c + be49e0c commit b123a24
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,3 @@ Remaining todos include:
* Tests and test coverage
* TravisCI
* Improved documentation
* `createStreamedResponse()`
24 changes: 24 additions & 0 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use Symfony\Component\HttpFoundation\StreamedResponse;

/**
* Factory class for PhpSpreadsheet objects.
Expand Down Expand Up @@ -56,4 +57,27 @@ public function createReader($type)
return new $readerClass();
}


/**
* Return a StreamedResponse containing the file
*
* @param Spreadsheet $spreadsheet
* @param unknown $type
* @param number $status
* @param array $headers
* @return \Symfony\Component\HttpFoundation\StreamedResponse
*/
public function createStreamedResponse(Spreadsheet $spreadsheet, $type, $status = 200, $headers = array())
{
$writer = IOFactory::createWriter($spreadsheet, $type);

return new StreamedResponse(
function () use ($writer) {
$writer->save('php://output');
},
$status,
$headers
);
}

}

0 comments on commit b123a24

Please sign in to comment.