Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/nbproject/
/nbproject/
/vendor
/.idea
/composer.lock
78 changes: 23 additions & 55 deletions FileDownloader/AppFileDownload.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,20 @@

namespace FileDownloader;

use Nette\Application\IResponse as IResponse2;
use Nette\Application\UI\Presenter;
use Nette\ComponentModel\Component;
use Nette\Http\IRequest;
use Nette\Http\IResponse;
use Nette\Http\Request;
use Nette\Http\Response;
use Nette\Http\Session;

/**
* @link http://filedownloader.projekty.mujserver.net
*
* @author Jan Kuchař
* @copyright  Copyright (c) 2014 Jan Kuchar
* @author Jan Kuchař
*
* @property Component $parent Parent component
*/
class AppFileDownload extends BaseFileDownload implements IResponse2 {
/**
* Parent of this object
* @var Component
*/
private $parent;
class AppFileDownload extends BaseFileDownload implements \Nette\Application\IResponse {

/**
* Downloader used to download file (optional)
Expand All @@ -68,63 +61,38 @@ class AppFileDownload extends BaseFileDownload implements IResponse2 {
private $downloader;

/**
* Getts new instance of self
* @param Component $parent
* @return AppFileDownload
* @var Request
*/
public static function getInstance(Component $parent) {
return new AppFileDownload($parent);
}
private $request;

/**
* @param Component $parent
* @var Response
*/
function __construct(Component $parent) {
parent::__construct();
$this->setParent($parent);
}
private $response;

/**
* Setts AppFileDownload parent
* @param Component $parent
* @return AppFileDownload
* @var Session
*/
function setParent(Component $parent) {
$this->parent = $parent;
return $this;
}
private $session;

/**
* Getts AppFileDownload parent
* @return Component
*/
function getParent() {
return $this->parent;
}

/**
* Implementation of IPresenterResponse::send()
*/
function send(IRequest $httpRequest, IResponse $httpResponse) {
parent::download($this->downloader);
public function __construct(Request $request, Response $response, Session $session) {
parent::__construct();
$this->request = $request;
$this->response = $response;
$this->session = $session;
}

/**
* Start download of the file!
* @param IDownloader $downloader
*/
function download(IDownloader $downloader = null) {
public function setDownloader(IDownloader $downloader) {
$this->downloader = $downloader;
}

// Call sendResponse on presenter (used since 2.0 instead of terminate)
if($this->parent instanceof Presenter) {
$presenter = $this->parent;
} else {
$presenter = $this->parent->lookup("Nette/Application/UI/Presenter",true);
}

$presenter->sendResponse($this);
/* Implementation of IPresenterResponse::send() */
public function send(IRequest $httpRequest, IResponse $httpResponse) {
parent::download($this->downloader, $this->request, $this->response, $this->session);
}

public function download(IDownloader $downloader = null, Request $request, Response $response, Session $session) {
throw new \LogicException('Use Presenter::sendResponse() to send response to client.');
}

}
Expand Down
Loading