Skip to content

Commit

Permalink
#345 - Implement static file downloader
Browse files Browse the repository at this point in the history
  • Loading branch information
johanjanssens committed May 16, 2020
1 parent 9cfc9eb commit 2aecc32
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
46 changes: 46 additions & 0 deletions code/site/components/com_pages/event/subscriber/downloader.php
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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
'subscribers' => [
'com://site/pages.event.subscriber.bootstrapper',
'com://site/pages.event.subscriber.redirector',
'com://site/pages.event.subscriber.downloader',
'com://site/pages.event.subscriber.dispatcher',
'com://site/pages.event.subscriber.pagedecorator',
'com://site/pages.event.subscriber.errorhandler',
Expand Down

0 comments on commit 2aecc32

Please sign in to comment.