-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#345 - Implement static file downloader
- Loading branch information
1 parent
9cfc9eb
commit 2aecc32
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
code/site/components/com_pages/event/subscriber/downloader.php
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,46 @@ | ||
<?php | ||
/** | ||
* Joomlatools Pages | ||
* | ||
* @copyright Copyright (C) 2018 Johan Janssens and Timble CVBA. (http://www.timble.net) | ||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> | ||
* @link https://github.com/joomlatools/joomlatools-pages for the canonical source repository | ||
*/ | ||
|
||
class ComPagesEventSubscriberDownloader extends ComPagesEventSubscriberAbstract | ||
{ | ||
protected function _initialize(KObjectConfig $config) | ||
{ | ||
$config->append(array( | ||
'priority' => KEvent::PRIORITY_HIGH, | ||
)); | ||
|
||
parent::_initialize($config); | ||
} | ||
|
||
public function onAfterApplicationRoute(KEventInterface $event) | ||
{ | ||
$request = $this->getObject('request'); | ||
$router = $this->getObject('com://site/pages.dispatcher.router.file', ['request' => $request]); | ||
|
||
if(false !== $route = $router->resolve()) | ||
{ | ||
//Qualify the route | ||
$path = (string) $router->qualify($route, true); | ||
|
||
//Set the location header | ||
$dispatcher = $this->getObject('com://site/pages.dispatcher.http'); | ||
|
||
try | ||
{ | ||
$dispatcher->getResponse() | ||
->setContent((string) $path, @mime_content_type($path) ?? 'application/octet-stream'); | ||
} | ||
catch (InvalidArgumentException $e) { | ||
throw new KControllerExceptionResourceNotFound('File not found'); | ||
} | ||
|
||
$dispatcher->send(); | ||
} | ||
} | ||
} |
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