-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented downloadable file tokens
Implemented helper methods for gateways to automatically convert file tokens into download URIs.
- Loading branch information
Showing
9 changed files
with
194 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Terminal42\NotificationCenterBundle\Controller; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpFoundation\StreamedResponse; | ||
use Symfony\Component\HttpFoundation\UriSigner; | ||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Terminal42\NotificationCenterBundle\BulkyItem\BulkyItemStorage; | ||
|
||
#[Route('/notifications/download/{voucher}', 'nc_bulky_item_download', requirements: ['voucher' => BulkyItemStorage::VOUCHER_REGEX])] | ||
class DownloadBulkyItemController | ||
{ | ||
public function __construct( | ||
private UriSigner $uriSigner, | ||
private BulkyItemStorage $bulkyItemStorage, | ||
) { | ||
} | ||
|
||
public function __invoke(Request $request, string $voucher): Response | ||
{ | ||
if (!$this->uriSigner->checkRequest($request)) { | ||
throw new NotFoundHttpException(); | ||
} | ||
|
||
if (!$bulkyItem = $this->bulkyItemStorage->retrieve($voucher)) { | ||
throw new NotFoundHttpException(); | ||
} | ||
|
||
$stream = $bulkyItem->getContents(); | ||
|
||
$response = new StreamedResponse( | ||
static function () use ($stream): void { | ||
while (!feof($stream)) { | ||
echo fread($stream, 8192); // Read in chunks of 8 KB | ||
flush(); | ||
} | ||
fclose($stream); | ||
}, | ||
); | ||
|
||
$response->headers->set('Content-Type', $bulkyItem->getMimeType()); | ||
$response->headers->set('Cache-Control', 'no-cache, no-store, must-revalidate'); | ||
|
||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.